pstmt=conn.prepareStatement(sql);空指针异常 System.out.println(conn);为null
publicclassUserDao{//检查用户是否有publicbooleangetUserByUnamePass(Useruser){booleanflag=fal...
public class UserDao {
//检查用户是否有
public boolean getUserByUnamePass(User user) {
boolean flag=false;
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs = null;
String sql="";
try {
conn =DBConnPool.getConnection();
//conn=DBConnPool.getConnection();
System.out.println("222");
System.out.println(conn);
sql="select * from T_USERS where t_name=?";
System.out.println(user.getT_name()); //能打印出123
pstmt=conn.prepareStatement(sql);
System.out.println("111"); //打印不出来
pstmt.setString(1,user.getT_name());
rs = pstmt.executeQuery();
if(rs.next()){
if(user.getT_Userpass().equals(rs.getString("t_Userpass"))){
// 登录成功
// 将得到的数据传给下一个页面
flag=true;
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
DBConnPool.release(rs, pstmt, conn);
}
return flag;
} 展开
//检查用户是否有
public boolean getUserByUnamePass(User user) {
boolean flag=false;
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs = null;
String sql="";
try {
conn =DBConnPool.getConnection();
//conn=DBConnPool.getConnection();
System.out.println("222");
System.out.println(conn);
sql="select * from T_USERS where t_name=?";
System.out.println(user.getT_name()); //能打印出123
pstmt=conn.prepareStatement(sql);
System.out.println("111"); //打印不出来
pstmt.setString(1,user.getT_name());
rs = pstmt.executeQuery();
if(rs.next()){
if(user.getT_Userpass().equals(rs.getString("t_Userpass"))){
// 登录成功
// 将得到的数据传给下一个页面
flag=true;
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
DBConnPool.release(rs, pstmt, conn);
}
return flag;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询