Hi ,u can use following code to get connection with oracle database
public Connection getDBConnection(String dataSourceName, String dbName)
throws PasskeyException {
java.sql.Connection connection = null;
long timeNowiS = System.currentTimeMillis();
try {
logger.debug("Just entering getdbcon get App Name "+timeNowiS);
javax.sql.DataSource dataSource = null;
if (dbContextlist.containsKey(dataSourceName)) {
dataSource = (javax.sql.DataSource) dbContextlist.get(dataSourceName);
} else {
Context context = new InitialContext();
dataSource = (javax.sql.DataSource) context.lookup(dataSourceName);
dbContextlist.put(dataSourceName, dataSource);
context.close();
}
//PerformanceTimer time1=new PerformanceTimer();
String appName = PasskeyUtils.getAppName();
logger.debug("getdbcon get App Name "+appName);
String username = PropertyFileReader.getPasskeyProperty(dbName +"."+appName+
".username");
String password = PropertyFileReader.getPasskeyProperty(dbName + "."+appName+
".pwd");
if ((password == null) || password.trim().equals("")) {
throw new SQLException("no password --for db " + dbName+"user****"+username+"=="+appName);
}
connection = dataSource.getConnection(username, password);
connection.setCatalog(dbName);
} catch (java.sql.SQLException sqlEx) {
throw new PasskeyException("in servicelocator.getDBConnection",
sqlEx);
} catch (Exception genericEx) {
throw new PasskeyException("in servicelocator.getDBConnection",
genericEx);
}
logger.debug("Just exiting getdbcon get App Name "+timeNowiS+" and now it is "+System.currentTimeMillis());
return connection;
}
Thanks and Regards,
SACHIN S.TATHOD
Patni Computer System Ltd.
Magarpatta City, Cyber City,
Tower 3,Level I & II,
Hadapsar,Pune - 411028
Mobile No:- +91-9881239401
Email ID:-
[email protected]