Is a right behaviour on inserting a duplicate key? - Mailing list pgsql-jdbc

From Vernon Wu
Subject Is a right behaviour on inserting a duplicate key?
Date
Msg-id DBXT5JUT2YDAQL76C7A5NKCUR73HF.3e46a2f4@kimiko
Whole thread Raw
List 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



pgsql-jdbc by date:

Previous
From: Tom Lane
Date:
Subject: Re: patch for COPY
Next
From: "David Wall"
Date:
Subject: Re: Is a right behaviour on inserting a duplicate key?