public boolean login(String username, String passwo)
throws Exception {
/*
* 一、得到Connection 二、得到Statement 三、得到ResuleSet 四、rs.next()返回的是什么,就返回什么
*/
// 准备四大参数
String driverClassName = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/mydb3";
String mysqlUsername = "root";
String mysqlPassword = "12345678";
// 加载驱动类
Class.forName(driverClassName);
// 得到Connection
Connection con = DriverManager.getConnection(url, mysqlUsername,
mysqlPassword);
/*
* 一、得到preparedStatement 1.给出sql模版:所有的参数使用?代替
* 2.调用Connection方法,得到PreparedStatement
*/
String sql = "select * from t_user where username=? and password=?";
PreparedStatement pstmt = con.prepareStatement(sql);
/*
* 二、为参数赋值
*/
pstmt.setString(1, username);// 给第1个问号赋值,值为username
pstmt.setString(2, passwo);// 给第二个问号赋值,值为password
ResultSet rs = pstmt.executeQuery();// 调用查询方法,向数据库发送查询语句
return rs.next();
}