美文网首页
myeclipse jdbc数据连接池设置

myeclipse jdbc数据连接池设置

作者: eesly_yuan | 来源:发表于2014-07-30 15:04 被阅读517次

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>

  • 测试

jsp测试
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<sql:query var="rs" dataSource="jdbc/mysql">
select username, password from users
</sql:query>
</head>
<body>
<c:forEach var="row" items="${rs.rows}">
用户名 ${row.username}<br/>
密码 ${row.password}<br/>
</c:forEach> <br>
</body>
</html>
selvet测试
MyEclipse jdbc数据连接池的配置

相关文章

网友评论

      本文标题:myeclipse jdbc数据连接池设置

      本文链接:https://www.haomeiwen.com/subject/rkastttx.html