Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes What Would Cause A Method That Inserts Records To Throw An Exception? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "What Would Cause A Method That Inserts Records To Throw An Exception?" Watch "What Would Cause A Method That Inserts Records To Throw An Exception?" New topic
Author

What Would Cause A Method That Inserts Records To Throw An Exception?

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I use the MySQL database and the Tomcat 4.1.18 web server. I try to insert a record to a table message_thread in the MySQL database. The first column of that table is for the ID of each recored. I created that column (field) with INTEGER AUTO_INCREMENT. Therefore, I did not mention that field in the method that inserts records. I got an internal server error and the root cause is:

[ January 05, 2004: Message edited by: JiaPei Jen ]
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

try changing "stmt.execute();" to "stmt.executeUpdate();". Small difference, but I've seen some driver implementations flub the execute method. Besides, you're doing an insert anyways, so use the appropriate executeUpdate method!
This may not be the cause, but it's an easy check.
Jamie
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I have changed the statement to:

The error message is the same.
Let me ask this -- if we try to insert a null into a field that is defined as "NOT NULL", will we get an error message saying "trying to insert a null value into a field that is not supposed to be a null"? or an exception is thrown to us like what I got?
m bhramaresh
Greenhorn

Joined: Jan 09, 2004
Posts: 13
just check in the database whether to the field u r entering the null value is a not null field like it might be declared as a primary key,
just check this thing, just intimate if it is solved prior.
thnx
bhramaresh
 
GeeCON Prague 2014
 
subject: What Would Cause A Method That Inserts Records To Throw An Exception?