hi,
In our web-site
www.goku.co.jp , we have used Session beans to fire SQL queries on the database. To establish connection to the database, we have written a class with a static method.
This static method is used by all session beans.
public class DBConna {
public DBConna () {
}
/* static method to get connection to the database used by all session beans */
public static Connection getConnection()throws SQLException,EJBException{
InitialContext context=null;
try{
context=new InitialContext();
DataSource ds=(javax.sql.DataSource) context.lookup("gokuPool");
return ds.getConnection();
}catch(SQLException se){
System.out.println("Unable to get Connect DataBase ");
throw new SQLException("Unable to Connect DataBase");
}
catch(NamingException ne){
System.out.println("Unable to get Datascource Connection");
throw new EJBException(ne);
} finally {
try{
if(context != null) context=null;
}catch(Exception ne){
System.out.println("Error Closing Context");
throw new EJBException("Error Closing Context");
}
}
}
}
My concern is over the use of "static". Since just one copy of the method is created in memory, does it mean only one connection is used to serve all database queries ?