データベースへの追加機能で問題が発生しました。次のコードは ExecuteUpdate ステートメントでハングします。例外がスローされないため、何が問題なのかわかりません。
public static boolean addUser(User userToAdd) throws Exception {
boolean isAdded = false;
if (checkConnection()) {
try {
if (isUnique(userToAdd.getIdCardNumber())) {
PreparedStatement pstmt = connection.prepareStatement("INSERT INTO users SET "
+ "idCardNr = ?,nationality = ?,name = ?,"
+ "address = ?,photo = ?,status = ?,gender = ?,"
+ "nationalNr = ?,birthDate = ?,birthPlace = ?,"
+ "created = ?, country = ?");
pstmt.setString(1, userToAdd.getIdCardNumber());
pstmt.setString(2, userToAdd.getNationality());
pstmt.setString(3, userToAdd.getFullName());
pstmt.setString(4, userToAdd.getAddress());
pstmt.setString(5, userToAdd.getPhotoPath());
pstmt.setString(6, userToAdd.getStatus());
pstmt.setString(7, userToAdd.getGender());
pstmt.setString(8, userToAdd.getRegisterNumber());
pstmt.setString(9, userToAdd.getBirthday());
pstmt.setString(10, userToAdd.getBirthPlace());
java.sql.Timestamp current = new java.sql.Timestamp(System.currentTimeMillis());
userToAdd.setCreated(current);
pstmt.setTimestamp(11, userToAdd.getCreated());
pstmt.setString(12, userToAdd.getCountry());
int rowsAffected;
try {
rowsAffected = pstmt.executeUpdate();
} catch (SQLException e) {
throw new Exception("Exception while executing update: " + e.getMessage());
}
if (rowsAffected != 0) {
isAdded = true;
pstmt.close();
}
} else {
System.out.println("User already in database");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
return isAdded;
}
誰かがこれをデバッグする方法を教えてくれますか?