Tomcat JNDI

server.xml

      <Context docBase="2014" path="/2014" reloadable="true" source="org.eclipse.jst.jee.server:2014">
  <Resource name="jdbc/pxxy"  
  auth="Container"   type="javax.sql.DataSource"      
  maxActive="100"   maxIdle="6"   maxWait="8000"     
  removeAbandoned="true"  
  removeAbandonedTimeout="180"           
  username="root"     
  password="oywl"     
  driverClassName="com.mysql.jdbc.Driver"      
  url="jdbc:mysql://localhost:3306/pxxy">  
    </Resource>  

 

 

jsp

 

<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>

<html>
<head><title>JSTL中数据库操作标签</title></head>
<body>



<sql:setDataSource dataSource="jdbc/pxxy" var="pxxyds"/>
<sql:query var="result" dataSource="${pxxyds}">
	SELECT empno,ename,job,hiredate,sal FROM emp ;
</sql:query>
<h3>一共有${result.rowCount}条记录!</h3>
<table border="1" width="100%">
	<tr>
		<td>雇员编号</td>
		<td>雇员姓名</td>
		<td>雇员工作</td>
		<td>雇员工资</td>
		<td>雇佣日期</td>
	</tr>
	<c:forEach items="${result.rows}" var="row">
		<tr>
			<td>${row.empno}</td>
			<td>${row.ename}</td>
			<td>${row.job}</td>
			<td>${row.sal}</td>
			<td>${row.hiredate}</td>
		</tr>
	</c:forEach>

</body>
</html>

 

SQL

 

/*======================= 删除数据库 =======================*/
DROP DATABASE IF EXISTS pxxy ;
/*======================= 创建数据库 =======================*/
CREATE DATABASE pxxy ;
/*======================= 使用数据库 =======================*/
USE pxxy ;
/*======================= 删除数据表 =======================*/
DROP TABLE IF EXISTS emp ;
/*======================= 创建数据表 =======================*/
CREATE TABLE emp(
   empno			INT(4)			PRIMARY KEY,
   ename			VARCHAR(10),
   job				VARCHAR(9),
   hiredate			DATE,
   sal				FLOAT(7,2)
) ;
/*======================= 插入测试数据 =======================*/
INSERT INTO emp (empno,ename,job,hiredate,sal) VALUES (6060,'李小军','经理','2001-09-16',12000.30) ;
INSERT INTO emp (empno,ename,job,hiredate,sal) VALUES (7369,'董鸣楠','销售','2003-10-09',6500.90) ;
INSERT INTO emp (empno,ename,job,hiredate,sal) VALUES (8964,'李祺','分析员','2013-10-01',3000) ;
INSERT INTO emp (empno,ename,job,hiredate,sal) VALUES (7698,'张惠','销售','2009-03-12',2800) ;
INSERT INTO emp (empno,ename,job,hiredate,sal) VALUES (7782,'杨军','分析员','2005-01-12',5500) ;
INSERT INTO emp (empno,ename,job,hiredate,sal) VALUES (7762,'刘明','销售','2008-03-09',4000) ;
INSERT INTO emp (empno,ename,job,hiredate,sal) VALUES (7839,'王月','经理','2006-09-01',8500) ;

 

 

你可能感兴趣的:(tomcat)