那位哥们能举个通过jndi连接连接池的例子??多谢!!!
那位哥们能举个通过jndi连接连接池的例子??多谢!!! 问题点数:50、回复次数:2Top
1 楼wxyxl(断肠人)回复于 2002-04-22 09:22:06 得分 25
InitialContext initCtx = null;
try {
initCtx = new InitialContext();
DataSource ds = (javax.sql.DataSource)
initCtx.lookup("java:comp/env/jdbc/demoPool");
return ds.getConnection();
} catch(NamingException ne) {
log("Failed to lookup JDBC Datasource. Please double check that");
log("the JNDI name defined in the resource-description of the ");
log("EJB's weblogic-ejb-jar.xml file is the same as the JNDI name ");
log("for the Datasource defined in your config.xml.");
throw new EJBException(ne);
} finally {
try {
if(initCtx != null) initCtx.close();
} catch(NamingException ne) {
log("Error closing context: " + ne);
throw new EJBException(ne);
}
}Top
2 楼wangtaoyy(flow)回复于 2002-04-22 09:30:52 得分 25
InitialContext ctx = new InitialContext();
DataSource dataSource = (javax.sql.DataSource)
ctx.lookup("jdbc/dsName");
Connection conn = dataSource.getConnection();
或
InitialContext ctx = new InitialContext();
DataSource dataSource = (javax.sql.DataSource)
ctx.lookup("java:comp/env/jdbc/yourDSName");
//需要在发布描述文件中声明资源引用
Connection conn = dataSource.getConnection();
Top




