【JSP开源代码栏目提醒】:网学会员,鉴于大家对JSP开源代码十分关注,论文会员在此为大家搜集整理了“EX8-23.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("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); //加载JDBC驱动
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=school"; //school为你的数据库
String user="sa"; //连接数据库的用户名
String password="123"; //连接数据库的密码
Connection conn= DriverManager.getConnection(url,user,password); //数据库连接对象
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); //SQL语句对象
String sql="select Student.S_no,S_name,Grade from Student,SC where Student.S_no=SC.S_no and SC.C_no='2' and SC.Grade>85"; //创建SQL语句
ResultSet rs=stmt.executeQuery(sql); //执行SQL语句并取得结果集
%>
<table border width=60%>
<caption>查询选修课程2且成绩大于85的所有学生及具体成绩</caption>
<tr>
<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>
</tr>
<%}%>
</table>
<br>
<%
sql="select Student.S_no,S_name,Course.C_no,C_name,Grade from Student,SC,Course where Student.S_no=SC.S_no and SC.C_no=Course.C_no"; //创建SQL语句
rs=stmt.executeQuery(sql); //执行SQL语句并取得结果集
%>
<table border width=60%>
<caption>所有学生的,,选修的课程名及成绩</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(); //关闭结果集
stmt.close(); //关闭SQL语句对象
conn.close(); //关闭数据库
%>
</body>
</html>
上一篇:
EX8-22.jsp
下一篇:
她要是喜欢我