Обсуждение: SQLException and error code
Hi! I am using postgresql-8.0-310.jdbc3.jar in my application. In order to get the error code from an SQLException I have to use sqlexception.getSQLState(). Shouldn't it be getErrorCode()? Peter
Peter.Zoche@materna.de wrote: > I am using postgresql-8.0-310.jdbc3.jar in my application. > In order to get the error code from an SQLException I have > to use sqlexception.getSQLState(). Shouldn't it be > getErrorCode()? We get a SQLSTATE from the server already, so it makes sense to make that available via getSQLState(). What exactly do you suggest we return from getErrorCode()? -O
Because in the postgresql documentation you can find the following page: http://www.postgresql.org/docs/8.0/interactive/errcodes-appendix.html#ERRCOD ES-TABLE There you can see all ERROR CODES! So why is there a method getErrorCode(), if the only thing it does is to return zero? -----Ursprüngliche Nachricht----- Von: Oliver Jowett [mailto:oliver@opencloud.com] Gesendet: Dienstag, 26. Juli 2005 16:04 An: Peter.Zoche@materna.de Cc: pgsql-jdbc@postgresql.org Betreff: Re: [JDBC] SQLException and error code Peter.Zoche@materna.de wrote: > I am using postgresql-8.0-310.jdbc3.jar in my application. > In order to get the error code from an SQLException I have > to use sqlexception.getSQLState(). Shouldn't it be > getErrorCode()? We get a SQLSTATE from the server already, so it makes sense to make that available via getSQLState(). What exactly do you suggest we return from getErrorCode()? -O
On Tue, 26 Jul 2005 Peter.Zoche@materna.de wrote: > Because in the postgresql documentation you can find the following page: > > http://www.postgresql.org/docs/8.0/interactive/errcodes-appendix.html#ERRCOD > ES-TABLE > > There you can see all ERROR CODES! > > So why is there a method getErrorCode(), if the only thing it does > is to return zero? The table is mislabeled a little bit, these are actually SQL State codes. Note that getErrorCode returns an int, so certainly couldn't return a sql state like "0100C". Kris Jurka
Peter.Zoche@materna.de wrote: > Because in the postgresql documentation you can find the following page: > > http://www.postgresql.org/docs/8.0/interactive/errcodes-appendix.html#ERRCOD > ES-TABLE > > There you can see all ERROR CODES! Those codes are actually SQLSTATEs. > So why is there a method getErrorCode(), It's defined by the JDBC spec, we don't have any choice about whether it is there or not. > if the only thing it does > is to return zero? Back to my original question: what are you expecting it to return? It can't return a SQLSTATE because it returns an int and SQLSTATE is alphanumeric. We don't have any other useful error code. So we just return 0 because we have to return *something*. -O
To better support existing applications which (for reasons I don't really understand) rely on the vendor-specific errorCode instead of the ANSI-standard sqlState, you could implement getErrorCode as: return Integer.parseInt(getSqlState(), 36); -Kevin >>> Oliver Jowett <oliver@opencloud.com> 07/26/05 6:33 PM >>> Peter.Zoche@materna.de wrote: > Because in the postgresql documentation you can find the following page: > > http://www.postgresql.org/docs/8.0/interactive/errcodes-appendix.html#ERRCOD > ES-TABLE > > There you can see all ERROR CODES! Those codes are actually SQLSTATEs. > So why is there a method getErrorCode(), It's defined by the JDBC spec, we don't have any choice about whether it is there or not. > if the only thing it does > is to return zero? Back to my original question: what are you expecting it to return? It can't return a SQLSTATE because it returns an int and SQLSTATE is alphanumeric. We don't have any other useful error code. So we just return 0 because we have to return *something*. -O ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Kevin Grittner wrote: > To better support existing applications which (for reasons I don't > really understand) rely on the vendor-specific errorCode instead of the > ANSI-standard sqlState, you could implement getErrorCode as: > > return Integer.parseInt(getSqlState(), 36); Ow! It seems a bit pointless though, honestly.. Going to wait for a reply from the original poster, I still don't understand what Peter wants getErrorCode() to return.. -O
I only have been confused by the naming of the following page: http://www.postgresql.org/docs/8.0/interactive/errcodes-appendix.html Its called "Appendix A. PostgreSQL Error Codes", so getErrorCode() seems to be the best method! But confusion is cleared now. Peter Kevin Grittner wrote: > To better support existing applications which (for reasons I don't > really understand) rely on the vendor-specific errorCode instead of the > ANSI-standard sqlState, you could implement getErrorCode as: > > return Integer.parseInt(getSqlState(), 36); Ow! It seems a bit pointless though, honestly.. Going to wait for a reply from the original poster, I still don't understand what Peter wants getErrorCode() to return.. -O