jsp链接mysql出错,帮看一下这两个文件.
conn.java文件如下:package conn;
import java.sql.*;
public class conn {
String dbUrl = "jdbc:mysql://localhost:3306/user";
String dbUser = "root";
String dbPassword = "12345";
Connection connect = null;
ResultSet rs = null;
public conn() {
try {
Class.forName("org.gjt.mm.mysql.Driver");
}
catch(java.lang.ClassNotFoundException e) {
System.err.println( e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
try {
connect = DriverManager.getConnection(dbUrl,dbUser,dbPassword);
Statement stm = connect.createStatement();
rs = stm.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
return rs;
}
}
conn.jsp文件如下:
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page language="java" import="java.sql.*"%>
<jsp:useBean id="connBean" scope="page" class="conn.conn"/>
<html>
<head>
<title>使用Bean连接MYSQL数据库</title>
</head>
<body bgcolor="#FFCCCC">
<div align="center">
<table width="60%" border="1">
<tr>
<td width="50%" bgcolor="#CCCCFF">
<div align="center"><font color="#FF0033"><b>学号</b></font></div>
</td>
<td width="25%" bgcolor="#CCCCFF">
<div align="center"><font color="#FF0033"><b>姓名</b></font></div>
</td>
</tr>
<%
ResultSet rs = connBean.executeQuery("select * from info");
while (rs.next()){
%>
<tr>
<td width="50%">
<div align="center"><%=rs.getString(1)%></div>
</td>
<td width="25%">
<div align="center"><%=rs.getString(2)%></div>
</td>
</tr>
<%
}
rs.close();
%>
</table>
</body>
</html>
提示 while (rs.next()){ 这一行出错.
请问有没有好的连接方式.