开发者

Any gotchas in migrating database connectivity to DataSource?

Looking at some old application code which uses explicit driver loading as

Class.forNa开发者_StackOverflow中文版me(...).newInstance

I have been told to change this to use the Java 1.4.2 mechanism to establish a database connection using ContextLookup, and DataSource.

Are there any gotchas I should be aware of?


No, you can safely interchange between DriverManager#getConnection() and the DataSource#getConnection() approaches. You can keep the remnant of the JDBC code untouched as long as it is well-written as per the standard JDBC idiom, that is, acquiring and closing resources in the shortest possible scope.

The DataSource approach has however the additional benefit that you can easily introduce a connection pool without changing the JDBC code. A connection pool will greatly improve connecting performance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜