<%@ page import="java.lang.*,java.io.*,java.sql.*,java.util.*" contentType="text/html; charset=GBK"%>
<html>
<head>
<title>jsp 连接sql server数据库</title>
</head>
<body bgcolor="#ffffff">
<div align="center">
<h3>jsp 连sql Server 2000数据库</h3>
</div>
<%
Connection con;
Statement sql;
ResultSet rs;
try
{
Class.forName("sum.jdbc.odbc.JdbcOdbcDriber");
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}
try
{
con=DriverManager.getConnection("jdbc:odbc:sum","sa","");
sql=con.createStatement();
rs=sql.executeQuery("select * from students");
}catch(SQLException e)
{
e.printStackTrace();
}
%>
<table border="1" align="center">
<tr bgcolor=red>
<th>JOB_ID</th>
<th>JOB_DESC</th>
<th>MIN_LVL</th>
<th>MAX_LVL</th>
</tr>
{
<%while(rs.next()){%>
<tr>
<td><%=rs.getString(1)%></td> //就这里是不是要捕获异常啊!这么搞啊!
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
</tr>
<% }%>
<%
rs.close();
sql.close();
con.close();
%>
</table>
<%out.print("<center>如果能看到表格中的数据,说明连接成功</center>");%>
</body>
</html>