今天编了个jsp程序可javabean里的函数调用老是出错啊

littleredhat littleredhat 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
以下是我javabean的源代码,不知道是数据库连接有问题呢还是判断有问题啊

这是验证用户名和密码的小组建啊

输入的用户名userID,密码password

判断在数据库里是否存在用户用这个函数 isVlidUser()返回真就是存在啊

可老是返回false郁闷啊,数据库连接应该没问题的啊 我试过了啊用application程序,本人刚学java这方面的数据库api啊,希望高手指点啊 。

package jspregister;
import java.sql.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

public class RegisterBean {
private String userID=null;
private String password=null;
//bean属性设置
public String getUserID(){
return userID;
}
public void setUserID(String userID){
this.userID=userID;
}
public String getPassword(){
return password;
}
public void setPassword(String password){
this.password=password;
}
//在数据库中查找ID和密码,验证用户身份
public boolean isVlidUser(){
Connection conn=null;
try{
Class.forName("sun.jdbc.odbc.jdbcodbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:sqlserver","sa","307613");
//PreparedStatement pstmt=conn.prepareStatement("select * from userinfo where id=?");
// pstmt.setString(1,userID);
//ResultSet rs=pstmt.executeQuery();
PreparedStatement pstmt=conn.prepareStatement("select * from userinfo where userID='" +userID + "'and password='" + password + "'");
ResultSet rs=pstmt.executeQuery();
//String psw=rs.getString("password");
//System.out.println(psw);
if(!rs.next()){
//String pw=rs.getString("password");
//if(password.equals(pw)){
conn.close();
return true;
}
else {
conn.close();
return false;
//}
//}
//else{
// conn.close();
// return false;
}
}
catch (Exception ex){
ex.printStackTrace();
}
return false ;
}
}

...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
littleredhat
Web 开发 81,108 成员 341,721 内容