<!-- The contents of this file will be loaded for each web application -->
1.将tomcat的conf/目录下的context.xml 修改成如下的操作
<Context reload="true">
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<Resource
name = "jdbc/DBSource"
type ="javax.sql.DataSource"
maxActive = "4"
maxIdle="2"
username ="root"
maxWait ="5000"
driverClassName ="com.mysql.jdbc.Driver"
password ="admin"
url="jdbc:mysql://localhost:3306/person"
/>
<! name --数据源名
driverClassName 使用的JDBC驱动程序的完整类名
url 数据库
username 数据库的用户名
password 数据库的密码
type 指定该资源的类型,这里为DataSource
maxActive 可以同时为该连接池分配的活动连接实例的最大数
maxIdle: 该连接池中可空间的连接的最大数
maxWait 在没有可连接的时候连接池在抛出异常前等待的最大毫米数
validationQuery 在连接被返回应用程序前,连接池用来验证连接的sql查询语句
-->
</Context>
数据库中调用才有如下方式
<!-- Context context = new InitialContext();
DataSource ds = (DataSource)context.lookup("java:comp/enc/jdbc/DBSource");
Connection conn = ds.getConnection();
-->
2.将mysql驱动拷贝到tomcat/lib 目录下
3.over
转载于:https://my.oschina.net/zlp5201/blog/404188