testExecuteQuary.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<%@page import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'testExecuteQuery.jsp' starting page</title>
</head> <body>
<%
//student为数据库的名字
String url="jdbc:mysql://localhost:3306/student?useSSL=true";
String useName="root";
String password="2277092";
String sql=null;
Connection conn=null;
Statement stmt=null; //加载驱动类
try{
Class.forName("com.mysql.jdbc.Driver");
out.print("加载驱动类成功");
}
catch(ClassNotFoundException e){
out.print("加载驱动类时出现异常");
} try{
conn=DriverManager.getConnection(url,useName,password); stmt=conn.createStatement();
sql="select * from info";//info为表名 ResultSet rs=stmt.executeQuery(sql);
%> <center>
<table border="1" width="270" cellspacing="0" cellpadding="0">
<tr>
<td width=50 align="center" valign="middle">学号</td>
<td width="80" align="center">姓名</td>
<td width=140 align="center">电话</td>
</tr> <%
while(rs.next()){
int id=rs.getInt(1);
String name=rs.getString(2);
String phone=rs.getString(3);
%> <tr>
<td height="40" align="center" valign="middle"><%=id %></td>
<td align="center" valign="middle"><%=name %></td>
<td align="center" valign="middle"><%=phone %></td>
</tr> <%
}
rs.close();
stmt.close();
%>
</table>
</center> <%
}
catch(SQLException e){
out.print("出现SQLException异常");
}
finally{
try{
if(conn!=null){
conn.close();
}
}
catch(SQLException e){
out.print("关闭数据库连接时出现异常");
}
}
%>
</body>
</html>

最新文章

  1. android AsyncTask介绍
  2. 自动执行任务管理---TaskManage
  3. struct和typedef struct
  4. 利用Mahout实现在Hadoop上运行K-Means算法
  5. 【WPF】无边框窗体
  6. NovaMind使用教程
  7. titan
  8. 从手工测试转型web自动化测试继而转型成专门做自动化测试的学习路线。
  9. CSDN问答频道“华章杯”7月排行榜活动开始,丰厚奖品等你拿
  10. oracle定期运行job
  11. careercup-中等难度 17.4
  12. TCP/IP-TCP
  13. CFGYM 2013-2014 CT S01E03 D题 费用流模版题
  14. 各种语言一句话反弹shell
  15. OpenCV 之 图像分割 (一)
  16. iOS真机调试步骤(Xcode8.0以上版本)(2015年)
  17. 复旦大学2017--2018学年第二学期高等代数II期末考试情况分析
  18. curl的POST请求,封装方法
  19. 浏览器关闭,onunload和onbeforeunload的使用
  20. 有return的情况下try catch finally的执行顺序(转)

热门文章

  1. RESTClient - firefox插件
  2. MVC4 开篇
  3. 【转】【MySQL】SQLSTATE详解
  4. Linux 网络编程七(非阻塞socket:epoll--select)
  5. PHP基础01:环境搭建
  6. Windows下MemCache多端口安装配置
  7. C/C++指针内存分配小细节
  8. maven integration with eclipse 3.0.4 does not work with NTLM proxy
  9. 配置ipvsadm服务
  10. 每天一个linux命令(25):df 命令