【JSP开源代码栏目提醒】:网学会员为广大网友收集整理了,EX8-36.jsp,希望对大家有所帮助!
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="java.sql.*"%>
<!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=GB18030">
<title>
JSP通用范例大全</title>
</head>
<body>
<%Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //加载驱动
String url="jdbc:odbc:school"; //school为你的数据库
String user="sa"; //连接数据库的用户名
String password="123"; //连接数据库的密码
Connection conn= DriverManager.getConnection(url,user,pass
word); //数据库连接对象
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); //SQL语句对象
String sql="delete from Dept_age"; //SQL语句对象
stmt.executeUpdate(
sql); //执行SQL语句
sql="select * from Dept_age"; //创建SQL语句
ResultSet rs=stmt.executeQuery(sql); //执行SQL语句
%>
<table border width=60%>
<caption>将院系学生平均年龄都置零</caption>
<tr>
<th>院系</th>
<th>学生平均年龄</th>
</tr>
<%
while(rs.next()) {%>
<tr align=center>
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
</tr>
<%}%>
</table>
<%rs.close(); //关闭结果集
stmt.close(); //关闭SQL语句对象
conn.close(); //关闭数据库
%>
</body>
</html>