首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

处理获取数据库连接时的经典错误:Cannot create PoolableConnectionFactory

2013-12-26 
处理获取数据库连接时的经典异常:Cannot create PoolableConnectionFactory??? usernameroot??? passwo

处理获取数据库连接时的经典异常:Cannot create PoolableConnectionFactory
??? username="root"
??? password="root"
??? driverClassName="com.mysql.jdbc.Driver"
??? maxIdle="10"
??? maxWait="10000"
??? maxActive="100"
??? url="jdbc:mysql://localhost:3306/DB" />


2.在Tomcat中context.xml的</context>前添加如下代码:
??? <ResourceLink name="jdbc/DB" global="jdbc/DB" type="javax.sql.DataSourcer"/>

?

3.在所建项目中web.xml的</web-app>前添加如下代码:

??? <resource-ref>
?????? ?<description>DB Connection</description>
?????? ?<res-ref-name>jdbc/mbss</res-ref-name>
?????? ?<res-type>javax.sql.DataSource</res-type>
?????? ?<res-auth>Container</res-auth>
????</resource-ref>

?

4.在获得数据库连接池中这样写,如:

???????Context initCtx = new InitialContext();
?????? Context envCtx = (Context) initCtx.lookup("java:comp/env");
?????? DataSource ds = (DataSource) envCtx.lookup("jdbc/DB");
?????? con = ds.getConnection();

热点排行