public class Demo_14 {
public static void main(String[] args) throws Exception {
DriverManager.registerDriver(new Driver());
Connection con = DriverManager.getConnection(
"jdbc:mysql://127.0.0.1:3306/dbl", "root", "123456");
String sql = "SELECT*FROM user WHERE usename=? and root = ?;";
PreparedStatement pst = con.prepareStatement(sql);
Scanner sc = new Scanner(System.in);
System.out.println("请输入用户名");
String usename = sc.nextLine();
System.out.println("请输入密码");
String root = sc.nextLine();
pst.setString(1, usename);
pst.setString(2, root);
ResultSet result = pst.executeQuery();
if (result.next()) {
System.out.println("登陆成功");
} else {
System.out.println("登陆失败");
}
result.close();
con.close();
pst.close();
}
}
|
|