大家帮我看看,这个JAVABEAN和check两个代码,是关于连接数据库和登陆验证的,老是无法正确运行。有人看了说是check中的if(rs.next())有问题,哪位高人能帮我解答一下。
JAVABEAN:
package com.bwm.db;
import java.sql.*;
public class Condb{
String servername="localhost";
String drivername="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://servername:1433;DatabaseName=db_Scenince;user=sa;password=123";
Connection con=null;
ResultSet rs=null;
public Condb(){
try{
Class.forName(drivername);
}catch(java.lang.ClassNotFoundException e){
System.err.println(e.getMessage());
}
}
public ResultSet executeQuery(String sql){
try{
con=DriverManager.getConnection(url);
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(sql);
}catch(SQLException ex){
System.err.println(ex.getMessage());
}
return rs;
}
public int executeUpdate(String sql){
int result=0;
try{
con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
result=stmt.executeUpdate(sql);
}catch(SQLException ex){
System.err.println(ex.getMessage());
}
return result;
}
public void close(){
try{
if(rs!=null){
rs.close();
}
}catch(Exception e){
System.err.println(e.getMessage());
}
try{
if(con!=null){
con.close();
}
}catch(Exception e){
System.err.println(e.getMessage());
}
}
}