2 messages in com.mysql.lists.javaSQLException - getMessage() / getCaus...
FromSent OnAttachments
Paul Palaszewski14 Jul 2005 08:32 
Mark Matthews14 Jul 2005 08:53 
Subject:SQLException - getMessage() / getCause() ...
From:Paul Palaszewski (paul@bdm-systems.com)
Date:07/14/2005 08:32:56 AM
List:com.mysql.lists.java

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.java:2851) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:753) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3562) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1154) at com.mysql.jdbc.Connection.createNewIO(Connection.java:1818) at com.mysql.jdbc.Connection.<init>(Connection.java:405) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:268) at java.sql.DriverManager.getConnection(DriverManager.java:525) at java.sql.DriverManager.getConnection(DriverManager.java:171) at com.bdm.datasource.SimpleDataSource.establishConnection(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(Unknown Source) at [snip]

and I'm using following jdbc url: jdbc:mysql://localhost/bdm?autoReconnect=true&useServerPrepStmts=false&jdbcCompliantTruncation=false&zeroDateTimeBehavior=convertToNull

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?