毕业设计JSP Eclipse博客网站系统
更多更新更免费论文网,专业毕业设计论文,课程设计源代码,上机实习报告,实验报告请点击www.751com.cn,本网站仅贴出部分代码,需要完整代码的请联系站长QQ
Tomcat连接池配置示例文件,
dbtest.jsp
<%@ page language="java" import="java.sql.*,javax.naming.*,javax.sql.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'dbtest.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
Context ctx=null;
Connection cnn=null;
Statement stmt=null;
ResultSet rs=null;
try
{
ctx=new InitialContext();
if(ctx==null) throw new Exception("娌℃湁鍖归厤鐨勭幆澧?);
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/blog");
if(ds==null) throw new Exception("娌℃湁鍖归厤鏁版嵁搴?);
cnn=ds.getConnection();
stmt=cnn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sql="select * from H_USER";
rs=stmt.executeQuery(sql);
out.println("鏁版嵁搴撹繛鎺ユ甯革紒");
}catch(Exception ee){
out.println("connect db error:"+ee.getMessage());
}
finally
{
if(rs!=null)rs.close();
if(stmt!=null)stmt.close();
if(cnn!=null)cnn.close();
if(ctx!=null)ctx.close();
}
%>
</body>
</html>