问题描述
这个是我建的连接数据库的javabeanpackagecom;importjava.sql.*;publicclassDataBaseConnection{publicConnectionconn=null;publicResultSetrs=null;publicDataBaseConnection(){}publicvoidOpenConn()throwsException{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");conn=DriverManager.getConnection("jdbc:odbc:bus","","");}catch(SQLExceptione){System.err.println("执行有错误:"+e.getMessage());}}publicConnectiongetConn(){returnconn;}//显示查询publicResultSetexecuteQuery(Stringsql){rs=null;try{conn=DriverManager.getConnection("jdbc:odbc:bus","","");Statementstmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);rs=stmt.executeQuery(sql);}catch(SQLExceptionex){System.err.println("执行查询有错误:"+ex.getMessage());System.out.println("执行查询有错误:"+ex.getMessage());}returnrs;}//更新数据publicvoidexecuteUpdate(Stringsql){Statementstmt=null;rs=null;try{conn=DriverManager.getConnection("jdbc:odbc:bus","","");stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);stmt.executeUpdate(sql);stmt.close();conn.close();}catch(SQLExceptionex){System.err.println("执行插入有错误:"+ex.getMessage());System.out.println("执行插入有错误:"+ex.getMessage());}}//删除数据publicvoidexecuteDelete(Stringsql){try{conn=DriverManager.getConnection("jdbc:odbc:bus","","");Statementstmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);stmt.executeUpdate(sql);}catch(SQLExceptionex){System.err.println("执行删除有错误:"+ex.getMessage());System.out.println("执行删除有错误:"+ex.getMessage());}}publicvoidcloseConn(){try{conn.close();}catch(Exceptionend){System.err.println("执行关闭Connection对象有错误:"+end.getMessage());System.out.println("执行关闭Connection对象有错误:"+end.getMessage());}}}这个是登陆验证的要调用上面的javabean里的方法<%@pagecontentType="text/html;charset=GBK"language="java"import="java.sql.*"errorPage=""%><jsp:useBeanid="db"scope="page"class="com.DataBaseConnection"></jsp:useBean><%request.setCharacterEncoding("GB2312");Stringsql="select*fromuserwhereuserID='"+request.getParameter("userID")+"'andpassword='"+request.getParameter("password")+"'";db.OpenConn();ResultSetrs=db.executeQuery(sql);if(rs.next()){rs.close();session.setAttribute("userID",request.getParameter("userID"));%>我验证之后发现rs为空,请教高手为什么会这样
解决方案
解决方案二:
该回复于2011-03-28 15:12:32被版主删除
解决方案三:
把你的写的SQL打印出来在DB上去查.看有没有结果.要么就是你request.getParameter()没有值。为空。所以RS结果集里没有数据。
解决方案四:
我试了,不是这个原因
解决方案五:
你确定你的sql语句正确么?看你数据库中是否有数据。