提到的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 12:40:10 浏览: 60
已知某个值内容,要从整个数据库中所有表查找出对应的表名和字段-易语言
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;
}
阅读全文