From: | Vernon Wu <vernonw(at)gatewaytech(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Is a right behaviour on inserting a duplicate key? |
Date: | 2003-02-09 18:50:28 |
Message-ID: | DBXT5JUT2YDAQL76C7A5NKCUR73HF.3e46a2f4@kimiko |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
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
From | Date | Subject | |
---|---|---|---|
Next Message | David Wall | 2003-02-09 20:19:20 | Re: Is a right behaviour on inserting a duplicate key? |
Previous Message | Tom Lane | 2003-02-09 17:30:06 | Re: patch for COPY |