当前位置: 代码迷 >> Java Web开发 >> [求助]DBCP连接池出错
  详细解决方案

[求助]DBCP连接池出错

热度:298   发布时间:2007-06-18 14:27:40.0
[求助]DBCP连接池出错

在server.xml中配置如下:
<Context path="/Register" docBase="Register" debug="0"
crosscontext="true" reloadable="true">
<Resource name="jdbc/Register_db" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/Register_db">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>username</name>
<value>root</value>
</parameter>
<parameter>
<name>password</name>
<value>root</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/Register_db?useUnicode = ture&amp;characterEncoding = gb2312</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>5</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
</ResourceParams>
</Context>
在工程中的WEB.XML中配置如下:

<resource-ref>
<description>JNDI JDBC DataSource of Register</description>
<res-ref-name>jdbc/Register_db</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

然后在JAVA类中使用如下语句使用连接:
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env"); //这里是第38行
DataSource ds = (DataSource)envContext.lookup("jdbc/Register_db");
con = ds.getConnection();
return con;
报错:
Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.simon.db.DBConnection.getConnection(DBConnection.java:38)
at com.simon.db.DBConnection.main(DBConnection.java:66)

搜索更多相关主题的帖子: DBCP  name  parameter  Register  

----------------解决方案--------------------------------------------------------
问题解决,JAVA文件不可能调用TOMACT的配置文件!!!
----------------解决方案--------------------------------------------------------

问题已解决!


----------------解决方案--------------------------------------------------------
  相关解决方案