【JSP开源代码栏目提醒】:本文主要为网学会员提供EX8-38.jsp,希望对需要EX8-38.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>
<jsp:useBean id="connect" scope="page" class="test.myconnectdb"/>
<%
String sDBDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver"; //连接字
String url="jdbc:microsoft:
sqlserver://localhost:1433;DatabaseName=school"; //school为你的数据库
String user="sa"; //连接数据库的用户名
String password="123"; //连接数据库的密码
connect.connectdb(sDBDriver,url,user,pass
word); //数据库连接
String sql="select * from Student"; //创建SQL语句
ResultSet rs=connect.executeQuery(sql); //执行SQL语句
%>
<table border width=60%>
<caption>使用
JavaBean
查询学生数据库</caption>
<tr>
<th></th>
<th></th>
<th>性别</th>
<th>年龄</th>
<th>院系</th>
</tr>
<%
while(rs.next()) {%>
<tr align=center>
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
</tr>
<%}%>
</table>
<%rs.close(); //关闭结果集
connect.closeStmt(); //关闭SQL语句对象
connect.closeConn(); //关闭数据库
%>
</body>
</html>