J2EE+SQL数据库问题

来源:百度知道 编辑:UC知道 时间:2024/06/25 16:10:59
用JSP+SERLET+JAVABEAN+SQL做注册连到数据库 这个是连接数据库查询数据库是否存在的用户名 如果存在则返回值为0 不存在就返回1 表示注册成功 请高手帮到看下 怎么改??为什么每次都返回1
package test;
import java.sql.*;
import java.util.*;
public class consql{
String sDBDriver;
String sConnStr;
ResultSet rs;
public String getname(String stuid,String password){
String query="select * from stuinfo where stuid='"+stuid+"' and password='"+password+"'"; sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
sConnStr="jdbc:odbc:LocalServer";
try{
Class.forName(sDBDriver);
Connection connWeb=DriverManager.getConnection(sConnStr);
Statement stmt=connWeb.createStatement();
rs=stmt.executeQuery(query);
}
catch(Exception e){System.out.println(e);}
try{
if(rs.next())
{
return "1";
}
rs.close();
}catch(Exception e){System.out.println(e);}
return "0";
}

把你的关键代码发一下,大家帮你研究一下

把try{
if(rs.next())
{
return "1";
}
rs.close();
}catch(Exception e){System.out.println(e);}
return "0";
改成:if(rs.next()) return "1";return "0";