I have the following code segment to insert a sign on data which the userid is the primary key of the table:
PreparedStatement ps = null;
try {
getDBConnection();
dbConnection.setAutoCommit(false); // The first step of new user sign up
ps = dbConnection.prepareStatement(CREATE_USER_QUERY);
ps.setString(1, userName.trim());
ps.setString(2, password.trim());
int result = ps.executeUpdate();
if(result != 1) {
logger.error("Unable to create user. Duplicate Key: " + userName);
throw new SignOnDAODupKeyException("Unable to create user. " +
"Duplicate Key : " + userName);
}
} catch (SQLException se) {
logger.error("SQLException: "+se.getMessage());
throw new DAOSysException("SQLException: "+se.getMessage());
} finally {
closeAll(ps);
}
It seems to me that inserting a duplicate user would result an invalide retured value. Instead, the action leads to a
SQL
expection as
ERROR: Cannot insert a duplicate key into unique index pk_signon
Can some clarify the 7.3.1 JDBC driver specification or implement in this regards?
Thanks,
Vernon