get ClassCastException when getting database connection from JNDI
534692Feb 25 2008 — edited Feb 27 2008I tried to get database connection through datasource in AS server in my java code. But I got ClassCastException in run time. I wonder if I used the right class. I am using AS 10.1.3.3.
Can anyone help? thank you!
Exception: java.lang.ClassCastException: oracle_jdbc_driver_LogicalConnection_Proxy
My code is like this:
public static OracleConnection getJNDIConnection() {
OracleConnection conn = null;
DataSource ds =null;
try {
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Context initCtx = new InitialContext();
ds = (DataSource) initCtx.lookup("jdbc/DEAMS_CONNECTION_POOL");
System.out.println("Start getting connection.... " );
conn = (OracleConnection)ds.getConnection();
System.out.println("got connection. " );
} catch (SQLException e) {
System.out.println("Cannot get connection: " + e);
} catch (NamingException e) {
System.out.println("NamingException: " + e);
}
catch (Exception e) {
System.out.println("Exception: " + e);
}
return conn;
}
Message was edited by:
KateShan