Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

insert query not executing..

 
timothy smith
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello!

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
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
finally{
.. I CLOSE CONNECTION ,PREPAREDsTATEMENT
}

Herman
PS please post real code if possible instead of re-typing it.
 
timothy smith
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 35976
422
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Timothy,
Thanks for posting the solution so that others who see this thread in the future can benefit!
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!