Hi,
I am calling webservices deployed on glassfish. Sometimes I call a webservice that lists data and it returns a null, call it again and it returns data. What could be the cause for that.
Below is my code for the connections. I am using a connection pool set up on glassfish. Are there any flaws in my code? Please assist.
private static InitialContext getContext() throws NamingException{
if(ctx == null)
ctx = new InitialContext();
return ctx;
}
private static DataSource getDataSource(
String name) throws NamingException{
if(ctx == null){
DB_connection.getContext();
}
switch(defaultNum){
case MASTER:
if(dsMaster == null){
dsMaster = ds = (DataSource)ctx.lookup(name);
}
break;
case WEB:
if(dsWeb == null){
dsWeb = ds = (DataSource)ctx.lookup(name);
}
break;
case BIG_BLUE:
//Not is use for now
break;
}
return ds;
}
/**
* @return Connection for MasterDB
* @throws SQLException
*/
protected static Connection openMasterDatabase() throws SQLException{
defaultNum = MASTER;
try {
getDataSource(JNDI_MASTER);
if(dsMaster != null){
conn = dsMaster.getConnection();
}
}
catch (NamingException e) {
e.printStackTrace(System.err);
}
return conn;
}
/**
* @return Connection
*/
public static Connection openWebAppsDatabase() throws SQLException{
defaultNum = WEB;
try {
getDataSource(JNDI_WEB);
if(dsWeb != null){
conn = dsWeb.getConnection();
}
}
catch (NamingException e) {
e.printStackTrace(System.err);
}
return conn;
}