JDBC connect problem

If the connection failed, how can I know it is due to the username or password invalid? Because I want to seperate the processing logic for different error. such as

dbconn = DriverManager.getConnection(url,userid, password);

if(.....)

System.out.println("database username or password is incorrect.);

if (.....)

System.out.println("database driver is incorrect.);

[400 byte] By [henry_22a] at [2007-11-27 4:44:30]
# 1
by default, the getConnection method should throw a SQLException whenever an error has occurred.. i don't know if there is a better way to do this, but i will suggest you to compare the exception's message (e.getMessage()) to differentiate the type of exception.
JWKC-5ivea at 2007-7-12 9:56:32 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Hi,

Try using getErrorCode() method

try{}

catch(SQLException sqle)

{

int errornumber=sqle.getErrorCode();

}

suppose u get errornumber value as 1 for invalid unername and password....then

if(errornumber==1)

{

System.out.print("Invalid Username/password");

}

I m not sure what are the error codes for the diff error thrown...u need to check in command prompt what error code u got and then add respective error code value in ur if statements...

All the Best.

hetal_giria at 2007-7-12 9:56:33 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
yeah.. the getErrorCode() will return the vendor specific exception code for a particular exception... try to do a System.out.println(e.getErrorCode()) to see what sort of error code u'll get with different error...
JWKC-5ivea at 2007-7-12 9:56:33 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
Thank you very much!! I use getErrorCode() to get the error code
henry_22a at 2007-7-12 9:56:33 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...