Java连接websphere配置的连接池
这几天在弄websphere6.1的连接池,我配置好连接池后按'测试连接'按钮后是显示连接成功的,于是我在eclipse中做了一个小测试,试图使用连接池的时候,却报了一个类型转换失败的错误.获取连接池的代码如下:
private static Context getInitialContext() throws Exception { Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"); p.put(Context.PROVIDER_URL, "iiop://9.73.45.116:9989/"); p.put(Context.SECURITY_PRINCIPAL, "root"); p.put(Context.SECURITY_CREDENTIALS, "root"); return new InitialContext(p); } private static Connection getConnection() throws Exception { Context ctx = null; ctx = getInitialContext(); DataSource ds = (DataSource)ctx.lookup("jdbc/HosPool"); Connection conn = ds.getConnection(); return conn; }
2011-11-10 11:58:59 com.ibm.ws.naming.util.HelpersWARNING: jndiGetObjInstNoopjava.lang.ClassCastException: javax.naming.Reference incompatible with javax.sql.DataSource