主题:JSP连接SQL 2000
<%@ page contentType="text/html; charset=gb2312" import = "java.sql.*" %>
<html>
<head>
<title>
LibraryBooks
</title>
</head>
<body bgcolor="#ffffff">
<table border="3">
<tr>
<th>add to cart</th><th>title</th>
<% String mysql;
Connection con = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //加载JDBC驱动
con = DriverManager.getConnection("jdbc:odbc:Library","","");//连接数据库
Statement statement = con.createStatement() ;//创建语句对象
mysql="select name from Title5";//执行SQL语句
ResultSet rs = statement.executeQuery(mysql);
while(rs.next()){ //显示
out.println("<tr>\n<TD><INPUT TYPE="checkbox" NAME="12345687" VALUE="Discrete "></TD>");
out.println("<td>"+rs.getString("name")+</td>\n</tr>");
}
rs.close();
statement.close() ;
}
catch(Exception e){
out.println(e.getMessage() );
}
con.close() ;
%>
</table>
</body>
</html>
哪儿错了,连不上.数据库和表都是是建好了滴~
<html>
<head>
<title>
LibraryBooks
</title>
</head>
<body bgcolor="#ffffff">
<table border="3">
<tr>
<th>add to cart</th><th>title</th>
<% String mysql;
Connection con = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //加载JDBC驱动
con = DriverManager.getConnection("jdbc:odbc:Library","","");//连接数据库
Statement statement = con.createStatement() ;//创建语句对象
mysql="select name from Title5";//执行SQL语句
ResultSet rs = statement.executeQuery(mysql);
while(rs.next()){ //显示
out.println("<tr>\n<TD><INPUT TYPE="checkbox" NAME="12345687" VALUE="Discrete "></TD>");
out.println("<td>"+rs.getString("name")+</td>\n</tr>");
}
rs.close();
statement.close() ;
}
catch(Exception e){
out.println(e.getMessage() );
}
con.close() ;
%>
</table>
</body>
</html>
哪儿错了,连不上.数据库和表都是是建好了滴~