当前位置: 技术问答>java相关
使用连接池的错误提示
来源: 互联网 发布时间:2015-06-29
本文导语: 我用下列代码想从WebLogic中得到连接池中的连接时报错,错误信息如下: 连接池失败! java.sql.SQLException: The pool driver only works within the WebLogic server, it cannot be called directly in a client. Use the t3 driver. 我的...
我用下列代码想从WebLogic中得到连接池中的连接时报错,错误信息如下:
连接池失败!
java.sql.SQLException: The pool driver only works within the WebLogic server, it cannot be called directly in a client. Use the t3 driver.
我的代码如下:
try{
String strURL = null;
strURL = "jdbc:weblogic:pool:SQLPool";
Connection sqlCon = DriverManager.getConnection(strURL);
sqlCon.setCatalog("northwind");
}
catch(Exception err){
out.println("连接池失败!
");
out.println(err.toString());
}
这是为什么呢?
连接池失败!
java.sql.SQLException: The pool driver only works within the WebLogic server, it cannot be called directly in a client. Use the t3 driver.
我的代码如下:
try{
String strURL = null;
strURL = "jdbc:weblogic:pool:SQLPool";
Connection sqlCon = DriverManager.getConnection(strURL);
sqlCon.setCatalog("northwind");
}
catch(Exception err){
out.println("连接池失败!
");
out.println(err.toString());
}
这是为什么呢?
|
这是一个独立的application吧?
提示的信息的意思应该是
weblogic的连接池只能被运行在它内部的程序入servlet/jsp,ejb调用
提示的信息的意思应该是
weblogic的连接池只能被运行在它内部的程序入servlet/jsp,ejb调用
|
真么是这样连的呢?
要用jndi,datasource
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.");
} finally {
try {
if(initCtx != null) initCtx.close();
} catch(NamingException ne) {
log("Error closing context: " + ne);
throw new EJBException(ne);
}
}
要用jndi,datasource
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.");
} finally {
try {
if(initCtx != null) initCtx.close();
} catch(NamingException ne) {
log("Error closing context: " + ne);
throw new EJBException(ne);
}
}