提到的checkUserExistDao类中 checkIsExist(Stirg tel, Stringcode)方法(30分)。 1)已知注册用户的数据库表结构(User) Id:用户标识 tel:手机号码 code:验证码 如下所示请完成上述要求的代码编写(15分)。 注I:采用Statement 对象执行SQL语句; Connection对象的createStatement()方法创建Statement。 Public checkIsExist(String name){ Connection conn=null; PreparedStatement pstm=null;Statement stm =null; ResultSet rs=null; Class. forName("com. mysql. jdbc. driver"); String url="jdbc:mysql://localhost: 3306/20JK?useSSL=false&serverTimezone=UTC";
时间: 2023-12-06 19:40:10 浏览: 64
public boolean checkIsExist(String tel, String code) {
Connection conn = null;
Statement stm = null;
ResultSet rs = null;
boolean exist = false;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url, "username", "password");
stm = conn.createStatement();
String sql = "SELECT * FROM User WHERE tel='" + tel + "' AND code='" + code + "'";
rs = stm.executeQuery(sql);
if (rs.next()) {
exist = true;
}
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
}
if (stm != null) {
stm.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return exist;
}
阅读全文