// 1.注册驱动
Class.forName(“com.mysql.cj.jdbc.Driver”);
// 2.获取连接
conn = DriverManager.getConnection(“jdbc:mysql://127.0.0.1:3306/userdata”,
“root”, “root”);
// 3.获取数据库操作对象
stmt = conn.createStatement();
// 4.执行sql语句
String sql = “select * from t_user where username = '” + userLoginInfo.get(“userLoginName”)
- “’ and userpwd = '” + userLoginInfo.get(“userLoginPwd”) + “'”;
// 5.处理查询结果集
rs = stmt.executeQuery(sql);
if (rs.next()) {
loginSuccess = true;
}
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
} finally {
// 6.关闭资源
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (stmt != null) {