dbTalk Databases Forums  

SQLException - getMessage() / getCause() ...

mailing.database.mysql-java mailing.database.mysql-java


Discuss SQLException - getMessage() / getCause() ... in the mailing.database.mysql-java forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Paul Palaszewski
 
Posts: n/a

Default SQLException - getMessage() / getCause() ... - 07-14-2005 , 10:37 AM






Hi everybody!

This time I've got a simple question, probably for Mark. We have a
web-application where the user can edit database connection settings.
Now let's assume, the user made some mistake and connection fails and we
want to give the user a readable message, what went wrong. Usually the
mysql + connector/j msgs are not that bad, so we used to include them
directly in the generated html, but now I get a stack trace as part of
the String returned by getMessage(). Hm, I actually expected to have the
message by itself - and I believe some time ago I had just the message
by itself (probably with connector/j 3.0.x).

I'm using jdk 1.5.0_02, mysql 4.1.10 and tried connector/j 3.1.6-3.1.10
on a german windows xp sp2.

Although getCause() returns null, I can see with the debugger, that the
exception's cause is set to itself which is probably the cause for the
text is spits out. Here is an example for the getMessage() output.

[snip]
Server connection failure during transaction. Due to underlying
exception: 'java.sql.SQLException: Access denied for user
'bdm'@'localhost' (using password: YES)'.
** BEGIN NESTED EXCEPTION **
java.sql.SQLException MESSAGE: Access denied for user 'bdm'@'localhost'
(using password: YES) STACKTRACE: java.sql.SQLException: Access denied
for user 'bdm'@'localhost' (using password: YES) at
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:2851) at
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:753) at
com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java: 3562) at
com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:11 54) at
com.mysql.jdbc.Connection.createNewIO(Connection.j ava:1818) at
com.mysql.jdbc.Connection.<init>(Connection.java:4 05) at
com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:268)
at java.sql.DriverManager.getConnection(DriverManager .java:525) at
java.sql.DriverManager.getConnection(DriverManager .java:171) at
com.bdm.datasource.SimpleDataSource.establishConne ction(Unknown Source)
at com.bdm.datasource.SimpleDataSource.getConnection( Unknown Source) at
com.bdm.datasource.SimpleDataSource.getConnection( Unknown Source) at
com.bdm.db.driver.DriverWrapper.testConnection(Unk nown Source) at
[snip]

and I'm using following jdbc url:
jdbc:mysql://localhost/bdm?autoReconnect=true&useServerPrepStmts=false&jd bcCompliantTruncation=false&zeroDateTimeBehavior=c onvertToNull

Any ideas, why this is the way it is?

btw., getLocalizedMessage() retruns the same. OK, I could make an work
around and use only the text up to the first line break if the exception
is comming from mysql, but on the other hand I don't like work arounds
and will hopefully get a better idea from someone on the list?

I mean, if I print the exception message + the stack trace, I have the
stack trace twice which is probably not, what people need to have. Or
did I miss / set any option, I should not have set?

Thanks for comments and for any help. Best regards
Paul Palaszewski

--
--
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/
_/ Grenzgasse 111, Objekt 9/4
_/ 2340 Mödling
_/
_/ Ing. Paul Palaszewski, (Hons) B.Sc.
_/ E-Mail: mailtoaul.palaszewski (AT) bdm-systems (DOT) com
_/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/



--
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe: http://lists.mysql.com/java?unsub=my...ie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Mark Matthews
 
Posts: n/a

Default Re: SQLException - getMessage() / getCause() ... - 07-14-2005 , 10:54 AM






-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Paul Palaszewski wrote:
Quote:
Hi everybody!

This time I've got a simple question, probably for Mark. We have a
web-application where the user can edit database connection settings.
Now let's assume, the user made some mistake and connection fails and we
want to give the user a readable message, what went wrong. Usually the
mysql + connector/j msgs are not that bad, so we used to include them
directly in the generated html, but now I get a stack trace as part of
the String returned by getMessage(). Hm, I actually expected to have the
message by itself - and I believe some time ago I had just the message
by itself (probably with connector/j 3.0.x).

I'm using jdk 1.5.0_02, mysql 4.1.10 and tried connector/j 3.1.6-3.1.10
on a german windows xp sp2.

Although getCause() returns null, I can see with the debugger, that the
exception's cause is set to itself which is probably the cause for the
text is spits out. Here is an example for the getMessage() output.

[snip]
Server connection failure during transaction. Due to underlying
exception: 'java.sql.SQLException: Access denied for user
'bdm'@'localhost' (using password: YES)'.
** BEGIN NESTED EXCEPTION **
java.sql.SQLException MESSAGE: Access denied for user 'bdm'@'localhost'
(using password: YES) STACKTRACE: java.sql.SQLException: Access denied
for user 'bdm'@'localhost' (using password: YES) at
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:2851) at
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:753) at
com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java: 3562) at
com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:11 54) at
com.mysql.jdbc.Connection.createNewIO(Connection.j ava:1818) at
com.mysql.jdbc.Connection.<init>(Connection.java:4 05) at
com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:268)
at java.sql.DriverManager.getConnection(DriverManager .java:525) at
java.sql.DriverManager.getConnection(DriverManager .java:171) at
com.bdm.datasource.SimpleDataSource.establishConne ction(Unknown Source)
at com.bdm.datasource.SimpleDataSource.getConnection( Unknown Source) at
com.bdm.datasource.SimpleDataSource.getConnection( Unknown Source) at
com.bdm.db.driver.DriverWrapper.testConnection(Unk nown Source) at
[snip]

and I'm using following jdbc url:
jdbc:mysql://localhost/bdm?autoReconnect=true&useServerPrepStmts=false&jd bcCompliantTruncation=false&zeroDateTimeBehavior=c onvertToNull

Any ideas, why this is the way it is?

btw., getLocalizedMessage() retruns the same. OK, I could make an work
around and use only the text up to the first line break if the exception
is comming from mysql, but on the other hand I don't like work arounds
and will hopefully get a better idea from someone on the list?

I mean, if I print the exception message + the stack trace, I have the
stack trace twice which is probably not, what people need to have. Or
did I miss / set any option, I should not have set?

Thanks for comments and for any help. Best regards
Paul Palaszewski

Paul,

We don't use setCause() or any of the constructor signatures that take a
cause, because it doesn't work for JDK-1.3 (which we still have to
support unfortunately).

We do append "nested" exceptions to the message though where it makes
sense (only for network errors), for debugging purposes, and because
SQLException.set/getNextException() are for chained exceptions (i.e. a
list, not a causation relationship...a lot of this is being cleared up
for JDBC-4.0, btw).

It's the JDK that internally sets cause equal to itself when no cause
has been specified. There's a blog entry out there somewhere about this,
but can't dig it up off the top of my head. (something to do with an
optimization for the VM).

-Mark

- --
Mark Matthews
MySQL AB, Software Development Manager - Connectivity
www.mysql.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFC1oqrtvXNTca6JD8RAmNzAKCtQPfavV9ePfBJkpl6qV sa1OiLgACgxgFI
w4TM4YY2eiBQv/7E2gtiOrI=
=mPI0
-----END PGP SIGNATURE-----

--
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe: http://lists.mysql.com/java?unsub=my...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.