1. 将mysql驱动(最好和mysql版本配套的驱动)放置在Apache Tomcat 下的lib目录里面
2. 在java web项目的WEB-INF下的web.xml中添加
<resource-ref>
<description>mysql</description>
<res-ref-name>jdbc/mysql</res-ref-name> //(1)
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3.在项目的META-INF目录的context.xml里面添加
<Resourcename="jdbc/mysql" //(2) (1)与(2)的名字要一致
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/showtime" //数据库名在这修改
username="root"
password=