public static void queryLogin(String username, String ppwd){
try{
Class.forName(driver);
System.out.println("驱动加载失败!");
}catch (Exception e){
System.out.println(e.getMessage());
}
try{
conn = DriverManager.getConnection(url,user,pwd);
System.out.println("数据库连接成功!!");
}catch (Exception e){
System.out.println(e.getMessage());
}
try{
String sql = "select * from user where username='" + username + "' and password='"+ppwd+"'";
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
System.out.println(username+ppwd);
if (rs.next()){
checkConnection = 1;
name = rs.getString("username");
newPwd = rs.getString("password");
System.out.print(newPwd);
}else{
checkConnection = -1;
}
System.out.println(checkConnection);
rs.close();
ps.close();
}catch (Exception e){
System.out.println(e.getMessage());
}
System.out.println("数据库连接"+name+newPwd);
if (conn != null){
try{
conn.close();
}catch (Exception e){
System.out.println(e.getMessage());
}
}
}
|