Connecting to database from JAVA using JDBC??
one from DATASoURCE
second from DriverManager.getConnection
program using a DataSource and a PooledConnection is:
import javax.naming.*;
import javax.sql.*;
...
Context context = new InitialContext();
DataSource ds = (DataSource)ctx.lookup(
"jdbc/DataSource" );
Connection con = ds.getConnection(
"userID", "password" );
...
finally
{
if( con != null ) { con.close(); }
}
CONNECTION POOLING
a connection pool class overrides the close() method and marks the Connection as available. That's why it is important to ensure that close() is invoked. Otherwise, the pool considers the Connection to be in use and creates a new Connection the next time one is requested, losing the benefit of pooling.
-
Interview Candidate
- Feb 22nd, 2006
- 1
- 1383
Showing Answers 1 - 1 of 1 Answers
Related Answered Questions
Related Open Questions
Connecting to database from JAVA using JDBC??
one from DATASoURCE
second from DriverManager.getConnection
program using a DataSource and a PooledConnection is:
import javax.naming.*;
import javax.sql.*;
...
Context context = new InitialContext();
DataSource ds = (DataSource)ctx.lookup(
"jdbc/DataSource" );
Connection con = ds.getConnection(
"userID", "password" );
...
finally
{
if( con != null ) { con.close(); }
}
CONNECTION POOLING
a connection pool class overrides the close() method and marks the Connection as available. That's why it is important to ensure that close() is invoked. Otherwise, the pool considers the Connection to be in use and creates a new Connection the next time one is requested, losing the benefit of pooling.
Related Answered Questions
Related Open Questions