• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

executeUpdate() not working and no exception being thrown

 
Jc Frane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am having a problem on inserting a single row in my database. By the way, I am using WAMP with pre-installed MySQL into it.
My code runs successfully and it seems that there is no error. However the update on my table does not take place. Here is the code:



By the way, I am using javafx. I successfully displayed the contents in my tableview.
The method above is being called on button clicked.

So, what is wrong here? Is there a problem on the database itself or in the code?

Thank you so much in advance!

I am willing to display related codes in my project if it is necessary.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
} catch (Exception ex) {
ex.getMessage();


It looks like whatever exception is being thrown is being eaten up by that above line of code. Did you mean to print the stacktrace instead?
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This could be the problem:

If the insert fails for whatever reason, an SQLException is thrown and subsequently caught in this clause. But here the ex.getMesage() does nothing - the message is not printed out! You should use ex.printStackTrace() like you did in the second clause. (Note: if several catch clauses match the exception being thrown, only the first one gets executed! So the SQLException will never make it into your catch (Throwable e) clause.)

I'd suggest catching only the SQLException in this particular piece of code, as you really cannot do anything sensible about other exceptions or throwables that could potentially be thrown here, such as OutOfMemoryError or InterruptedException.

Another problem could be a missed commit: if the connection you're using has autocommit turned off (I can't tell as we don't see how you obtain the connection), you need to commit explicitly. If you don't, everything looks fine, but the changes are never seen in the database - like in your case.
 
Jc Frane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much guys, your replies solved my problem!

I am having a problem in the structure of my columns...

Again, thank you so much!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic