-
软件
myeclipse2014
tomcat8.x
jdbc:mysql-connector-java-5.1.26-bin.jar
-
添加jdbc库。
将jdbc复制到“工程文件夹/WebRoot/WEB-INF/lib”文件夹下,在工程右键添加一个userlib.
-
建立context.xml文件。
在“工程文件夹/WebRoot/META-INF”下,新建context.xml文件。
<?xml version="1.0" encoding="UTF-8"?> <Context debug="5" reloadable="true"> <Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="root" password="" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/> </Context>
-
修改web.xml文件
在web.xml文件中添加以下内容:
<resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/mysql</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
-
测试