A Datasource like ConnectionPoolDataSource or an XADataSource, are all configured on a directory server by an administrator. Use JNDI to retrieve the logical datasource and use DataSource to get the connection.
Public API: (This is a sample code, not shippable code).
public Connection getDatabaseConnection() {
Context context = null ;
DataSource ds = null ;
Connection conn = nll ;
try {
context = new InitialContext() ;
ds = (DataSource)context.lookup("Logical datasource name") ;
conn = ds.getConnection() ;
}catch(Exception e){
-- Implement exception handling ;
}
return conn ;
}
Public API: (This is a sample code, not shippable code).
public Connection getDatabaseConnection() {
Context context = null ;
DataSource ds = null ;
Connection conn = nll ;
try {
context = new InitialContext() ;
ds = (DataSource)context.lookup("Logical datasource name") ;
conn = ds.getConnection() ;
}catch(Exception e){
-- Implement exception handling ;
}
return conn ;
}
No comments:
Post a Comment