<%@ page contentType="text/html; charset=GB2312" language="java" errorPage="" %>
<%@ page import="java.sql.*" %>
<html>
<head><title>桥连接数据库</title></head>
<%
Connection conn=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String strConn="jdbc:odbc:shopdata";
String strUser="sa";
String strPassword="";
conn=DriverManager.getConnection(strConn,strUser,strPassword);
out.println("<h2>JDBC-ODBC桥连接数据库成功!</h2>");
Statement stmt=conn.createStatement();
String strSql="SELECt TOP 5 学号,姓名,数学成绩,英语成绩,物理成绩 FROM students order by 英语成绩";
ResultSet rs=stmt.executeQuery(strSql);
rs.first();
}
catch(ClassNotFoundException e)
{
out.println(e.getMessage());
}
catch(SQLException e)
{
out.println(e.getMessage());
}
finally
{
try
{if(conn!=null)
conn.close();
}
catch(Exception e)
{}
} %>
<center><h2>英语成绩前5名的学生列表</h2></center>
<table border=1 align=center>
<tr>
<th>学号</th>
<th>姓名</th>
<th>数学成绩</th>
<th>英语成绩</th>
<th>物理成绩</th>
</tr>
<% while(rs.next()){%>
<tr bgcolor="lightblue">
<td><%=rs.getString("姓名") %></td>
<td><%=rs.getString("学号") %></td>
<td><%=rs.getString("数学成绩") %></td>
<td><%=rs.getString("英语成绩") %></td>
<td><%=rs.getString("物理成绩") %></td>
<% } %>
</html>