本文章记录我在JSP中配置MySQL数据池的过程。

1.首先要保证mysql-connector-java.x.xx.jar驱动包要放在Tomcat 目录下的lib目录下。

2.修改当前工程部署所在的Server的context.xml文件,在<Context>和</Context>中间添加如下内容:

<Resource name="jdbc/mysql"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="username"
password="password"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mysql?autoReconnect=true"/>

参数说明:mysql:你要连接的数据库名

                    username:mysql的用户名

                    password:你的密码

3.在当前工程的WEB-INF下得web.xml添加如下内容:

<description>MyBlog</description>
<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>

参数说明:mysql:你要连接的数据库名

然后重启Tomcat服务,OK。接下来要解决MySQL乱码问题。