views:

301

answers:

2

I have recently changed an application from storing the database username and password in a configuration file (gasp password stored in plain text in a config file, I know, I know).

The application now asks the user to type in her username and password before it can continue.

The new version of the application now has to interrogate the SQLException to determine what caused the exception (invalid user name or password, database server unreachable, connection timeout, etc.) so that it can decide what to do next (prompt the user to correct the username and password, tell the user to try again later once the network issue has been sorted, reconnect invisibly, etc.).

Trying to find the SQLException errorCodes (SQLException.getErrorCode()) that relate to these (and other) causes has been near to impossible and we have been forced to guessing (which at times can be dangerous).

The Java API docs say this is vendor-specific.

Does anyone have the error-codes that can be set by the Sybase JConnect JDBC drivers?

  • JRE 1.5
  • jConnect for JDBC 2.0 (spec version 5.2)
  • Sybase IQ 12.7
+1  A: 

You mean these?

18Rabbit
Would be great to actualy post the list here so that if the link goes dead at some future time, but I am not sure how copyright works in that regard.
Ron Tuffin
+1  A: 

It seems that most of the errorCodes in the caught SQLException are 0.

That means you have to check the Connection/Statement/ResultSet's SQLWarnings

connection.getWarnings();

or the exceptions chained on to the thrown exception

sqlException.getNextException();

the tricky thing here is that the chained exceptions might be SQLExceptions or IOExceptions, and possibly others (I can't remember coming across others).

Ron Tuffin