1、在tomcat安装目录下的lib目录下导入数据驱动包 mysql-connector-java-5.0.8-bin.jar。
2、在context中配置数据源。有5个位置可以配置参考tomcat文档:
只对这个项目起作用
In an individual file at/META-INF/context.xmlinside the application files. Optionally (based on the Host's copyXML attribute) this may be copied to$CATALINA_BASE/conf/[enginename]/[hostname]/and renamed to application's base file name plus a ".xml" extension.
对CATALINA_BASE下的项目都起作用
In individual files (with a ".xml" extension) in the$CATALINA_BASE/conf/[enginename]/[hostname]/directory. The context path and version will be derived from the base name of the file (the file name less the .xml extension). This file will always take precedence over any context.xml file packaged in the web application's META-INF directory.
对所有的tomcat下目录起作用
Inside a Host element in the mainconf/server.xml.
- In the
$CATALINA_BASE/conf/context.xmlfile: the Context element information will be loaded by all web applications. - In the
$CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.defaultfile: the Context element information will be loaded by all web applications of that host.
<?xml version="1.0" ?>
<Context>
<Resource name="mySource"
auth="Container"
type="javax.sql.DataSource"
username="root"
password="123456"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql:///dayjdbc"
maxActive="8"
maxIdle="4"/>
</Context>
本文介绍如何在Tomcat服务器中配置MySQL数据源,包括在lib目录放置mysql-connector-java-5.0.8-bin.jar驱动包,以及通过不同层级的context.xml文件设置数据源参数。

2769

被折叠的 条评论
为什么被折叠?



