File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes PreparedStatement's Error Reporting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "PreparedStatement Watch "PreparedStatement New topic

PreparedStatement's Error Reporting

Chinmay Bajikar
Ranch Hand

Joined: Dec 08, 2001
Posts: 159
Hi all,
I have a PreparedStatement object with a proper query and data set to it.
But when I fire the query(executeUpdate()) it throws as SQLException saying Column length too small for Value.
How Do i know the particular field for which this error was flagged?
Does the SQLException or PreparedStatement object
give me any such sort of information??
Thanks in advance,

The strength of the Wolf is the pack & the strength of the pack is the wolf....Rudyard Kipling
Michael Zalewski
Ranch Hand

Joined: Jun 10, 2002
Posts: 30
You don't even say what database you are using. Or what the text of the PreparedStatement is. Or what JDBC driver you are using, version of JDK, etc. All of this could matter.
However, in general, no you will not be able to tell what column, not from the error message that comes out of the PreparedStatement. Check the lengths of your strings against the declared lengths of the columns in the database. Trying to put 'ABCDE' into a column that is declared CHAR(4), and will give this error. Check the precision and scale of the numbers against the definitions in the database. Trying to put 100.0 or 0.33 into a column declared as NUMBER(2,1) will not work either.
Christopher Dixon

Joined: Jan 30, 2002
Posts: 22
The JDBC drivers for most databases (Oracle, DB2, SQLServer, etc) are notoriously horrible at giving error messages. You're usually much better off (if you can) to look in the server logs. If you're using type 2 drivers (like the oracle OCI or DB2Connect), you can also turn up the client side logging and get more info. If you can't get to the logs, poke and hope, like Michael said.
I agree. Here's the link:
subject: PreparedStatement's Error Reporting
It's not a secret anymore!