ok... that makes perfect sense to me, however, I still have one problem... what class am I missing an import for?
here is what I currently have, I must be missing something because NetBeans doesn't know what NamingException, or InitialContext is.
import java.util.Hashtable;
import javax.sql.*;
import java.sql.*;
Thanks,
Rick
Main Topics
Browse All Topics





by: petiexPosted on 2008-01-13 at 20:43:13ID: 20650924
It looks like you are casting your DataSource to two different implementations in the executeQuery and executeUpdate methods, that is, com.mysql.jdbc.jdbc2.optio nal.MysqlC onnectionP oolDataSou rce and com.sun.appserv.jdbc.DataS ource, respectively. I believe you will have better luck if, in both cases, instead of casting the DataSource as any implementation, you simply cast it as the javax.sql.DataSource. I access connection pools for a few different database types (DB2, Derby, Cache) deployed on glassfish for several applications at work, and this is the method I use for all of them:
/**
* Returns the DataSource object for the given jdbc resource name
* @param dsName name for a jdbc resource ("jdbc/something_Pool")
* @return the DataSource object for the given jdbc resource name
*/
public static DataSource getDataSource(String dsName)
throws NamingException {
InitialContext context = null;
context = new InitialContext();
DataSource dataSource = (DataSource) context.lookup(dsName);
return dataSource;
}