解决方案 »
- @Transactional标注的类 如果类中抛出异常
- 如何在IE中访问servlet(新手问题)
- 我的eclipse里项目不部署玩不能开启tomcat了
- <img src。。。。。的问题,有5行源码!!
- Hibernate中调用存储过程,调用几次hibernate就死掉了
- 字符串拆分的问题,高手也来看看吧,不一定能解决
- 100分的问题赶快解决
- 聊天室中的显示在线人数和显示登陆用户姓名?
- 高分求解(大虾看过来)
- 怎样把ResultSet对象Serializable,从而可以通过Servlet传给Applet ?
- easyUI的panel弹不出来?
- 请教一个关于servlet 中out.flush无效的问题
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<resource-ref>
<description>MySQL DB Connection Pool</description>
<res-ref-name>jdbc/DBPool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
<Resource
name="jdbc/DBPool"
global="jdbc/DBPool"
type="javax.sql.DataSource"
username="root"
password="root"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
url="jdbc:mysql://127.0.0.1:3306/test"
maxActive="4"/> </GlobalNamingResources>
<!-- The contents of this file will be loaded for each web application -->
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<ResourceLink
name="jdbc/DBPool"
type="javax.sql.DataSource"
global="jdbc/DBPool"
/>
</Context>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>vistDBTest</title>
</head>
<body>
<% //注册数据库驱动
Class.forName("com.mysql.jdbc.Driver");
//获取数据库连接
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
//创建Statement对象
Statement stmt = conn.createStatement();
//执行查询,获取ResultSet对象
ResultSet rs = stmt.executeQuery("select * from email");
%>
<table bgcolor="#9999dd" border="1" width="400">
<% //遍历结果集
while(rs.next())
//输出表格行
out.println("<tr>");
//输出表格列
out.println("<td>");
//输出结果集的第二列的值
out.println(rs.getString(1));
//关闭表格列
out.println("</td>");
//开始表格列
out.println("<td>");
//输出结果集的第三列的值
out.println(rs.getString(2));
//关闭表格列
out.println("</td>");
//关闭表格行
out.println("</tr>");
%>
</table>
</body>
</html>