一、在項(xiàng)目中的配置:
.在WebRoot/META-INF下建context.xml文件,注意必須在該目錄下:
<?xml version="1.0" encoding="UTF-8"?>
<Context reloadable="true" crossContext="true">
<Resource
name="jdbc/項(xiàng)目名" ---------------必須為項(xiàng)目名,否則會(huì)有異常
auth="Container"---------------------該項(xiàng)為不變項(xiàng)
type="javax.sql.DataSource"---------該項(xiàng)為不變項(xiàng)
driverClassName="com.mysql.jdbc.Driver"------------數(shù)據(jù)庫(kù)驅(qū)動(dòng)名
url="jdbc:mysql://localhost:3306/haotian?autoReconnect=true"---url
username="root"---------------------------------------用戶名
password="root"----------------------------------------密碼
maxActive="10" ----------------------------最大連接數(shù)
maxIdle="5" -------------------------------最大空閑連接數(shù)
maxWait="-1"/> ------------------最大等待毫秒數(shù),-1為無(wú)限等待
</Context>
在Tomcat6.0以后就不需要在web.xml中配置了:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/blog</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
二、配置過程中遇到的異常及解決方法:
(1)org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
解決方法:連接池的名字是name="jdbc/項(xiàng)目名"
(2)org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
解決方法:必須把mysql的驅(qū)動(dòng)包,拷貝到tomcat/lib目錄下
(3)javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
這個(gè)異常可能是使用tomcat6版本以下,需要在項(xiàng)目的web.xml配置:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/blog</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
以上是個(gè)人在開發(fā)過程中遇到的異常,在參考網(wǎng)友提供解決及個(gè)人實(shí)踐總結(jié)所得。
posted on 2009-07-04 21:24
田園風(fēng)光 閱讀(553)
評(píng)論(0) 編輯 收藏