The moose likes JDBC and Relational Databases and the fly likes insert query not executing.. 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 "insert query not executing.." Watch "insert query not executing.." New topic

insert query not executing..

timothy smith

Joined: Jun 07, 2007
Posts: 11

in my project i use an insert query .. i dont get any exceptions and the project runs normally but when i check my database the new data hasnt been added! what could go wrong?

here is my code:

any ideas??
Herman Schelti
Ranch Hand

Joined: Jul 17, 2006
Posts: 387
hi Timothy,

some hints:

-log your sql-exceptions in the catch block, seewhat you will get.
catch (SQLException ex) {
//log here

-do the closing in a finally block (not in the catch block)

PS please post real code if possible instead of re-typing it.
timothy smith

Joined: Jun 07, 2007
Posts: 11
hello! i just thought to write the code which had to do with the problem.. i use finally block and catch all sql exception.. eventually my problem turned out to be not the query but something else..(?)
i have made a little test and tried to execute the query
"insert into my_table (USER_ID, MOVIE_CAT1)values (?, 1)" but no new data was added in the table, when still i get no message for exception .

i have several other functions for writing in the databasewhich work fine!i created the table using mySqlAdministrator and when i make the query in mySqlQueryAnalyzer it works perfectly!

what could cause this problem?
timothy smith

Joined: Jun 07, 2007
Posts: 11
hello again!

it turned out that the problem had to do with an option in mySqlAdministrator!

i had used navicat to create the other tables. as for the table i wanted to add information, it was created using MySQLAdministrator. Another engine instead of ISAM which was the option for all the other tables in database was set by default!

when i changed that it worked! if anyone knows why this happened it would be interesting to know!
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

Thanks for posting the solution so that others who see this thread in the future can benefit!

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: insert query not executing..
jQuery in Action, 3rd edition