views:

30

answers:

1

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

Class.forName(...).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?

+1  A: 

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.

BalusC