我正在尝试检查数据库中是否已存在特定值。谁能告诉我,我的陈述有什么问题?而且我也不能将数据插入MySQL。谢谢
try {
Statement s = c.createStatement();
final String queryCheck = "SELECT COUNT(*)FROM pengguna WHERE pengguna.username = '"+ username +"'";
final PreparedStatement ps = c.prepareStatement(queryCheck);
ps.setString(1, username);
final ResultSet resultSet = ps.executeQuery();
if(resultSet.next()) {
final int count = resultSet.getInt(1);
}
else{
this.sql = "INSERT INTO pengguna (password, username, nama, umur, agama, pekerjaan, alamat) "
+ "VALUES ('"+ password +"', '"+ username +"', '"+ nama +"', '"+ umur +"', '"+ agama +"', '"+ pekerjaan +"', '"+ alamat +"')";
s.executeUpdate(sql);
}
} catch(SQLException e) {
System.out.println("Error pada method setInsert()");
return;
}