Home > Archive > PostgreSQL JDBC > July 2005 > SQLException and error code









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author SQLException and error code
Peter.Zoche@materna.de

2005-07-26, 9:24 am

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


---------------------------(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

Oliver Jowett

2005-07-26, 9:24 am

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

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Peter.Zoche@materna.de

2005-07-26, 9:24 am

Because in the postgresql documentation you can find the following page:

http://www.postgresql.org/docs/8.0/...dix.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 & #91;mailto:oliver@op
encloud.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

---------------------------(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

Kris Jurka

2005-07-26, 11:24 am



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/...dix.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


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Oliver Jowett

2005-07-26, 8:24 pm

Peter.Zoche@materna.de wrote:
> Because in the postgresql documentation you can find the following page:
>
> http://www.postgresql.org/docs/8.0/...dix.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

2005-07-28, 11:36 am

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


Peter.Zoche@materna.de wrote:[color=darkred
]
> Because in the postgresql documentation you can find the following

page:

>
>

http://www.postgresql.org/docs/8.0/...dix.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


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Oliver Jowett

2005-07-28, 8:24 pm

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

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Peter.Zoche@materna.de

2005-07-29, 3:24 am

I only have been confused by the naming of the following page:

http://www.postgresql.org/docs/8.0/...s-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

---------------------------(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

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com