首页 > 其他分享 >获取用户输入的用户和密码,然后使用封装后的jdbc来查库进行验证用户名和密码是否正确

获取用户输入的用户和密码,然后使用封装后的jdbc来查库进行验证用户名和密码是否正确

时间:2023-01-12 19:12:21浏览次数:38  
标签:jdbc 用户 System 密码 用户名 查库 输入 out

public class Test02 {
//    获取用户输入的用户和密码,然后使用封装后的jdbc来查库进行验证用户名和密码是否正确
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        Connection coon = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/db4?useSSL=false&useUnicode=true&characterEncoding=UTF-8",
                "root",
                "123456");
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入用用户名:");
        String name = scanner.next();
        System.out.print("请输入密码:");
        int pwd = scanner.nextInt();
        String sql = "select * from admin where name ='" + name +"' and pwd = " + pwd ;
        Statement statement = coon.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);
        if (resultSet.next()){
            System.out.println("密码输入正确");
        }else {
            System.out.println("输入错误");
        }
        resultSet.close();
        statement.close();
        coon.close();
    }
}

 

标签:jdbc,用户,System,密码,用户名,查库,输入,out
From: https://www.cnblogs.com/p1121/p/17047690.html

相关文章