标题:jsp连接mysql不上,请教
取消只看楼主
guixiaolan
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:356
专家分:0
注 册:2006-4-20
 问题点数:0 回复次数:0 
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()){ 这一行出错.
请问有没有好的连接方式.
搜索更多相关主题的帖子: jsp mysql 
2008-02-28 22:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-201337-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.334851 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved