• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is this not working?

 
ben riches
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I had this problem earlier and someone suggested to use the setAutoCommit() method. Well I did try it and I am still getting the same problem as below. Is there something wrong with how I have constucted my setAutoCommit method and the other methods that work with it?
PROBLEM:
I have an sql statment, inside a loop so each loop though it will insert the right data to the database. Lets say the code is going to loop 4 times. The problem is I have an error in my sql statement on the last loop, the 3 previous loops will execute but the last loop will thow an exception. This is not what I want, I want the code to thow the exception first before any data is executed to the database if there is an exception, if not then execute the data.

Thanks
Ben
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Until you execute the connection's commit() method, the changes you have made (i.e. the inserts) are not applied to the database. So, when you rollback(), it is as though you never executed the inserts. So, I'm not sure why their suggestion to use setAutoCommit(false)/commit()/rollback() is not working for you.
Is it an SQLException that occurs, or some other exception (e.g. IndexOutOfBounds, etc)?
 
ben riches
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Blake Minghelli:
Until you execute the connection's commit() method, the changes you have made (i.e. the inserts) are not applied to the database. So, when you rollback(), it is as though you never executed the inserts. So, I'm not sure why their suggestion to use setAutoCommit(false)/commit()/rollback() is not working for you.
Is it an SQLException that occurs, or some other exception (e.g. IndexOutOfBounds, etc)?


Hello
The Exeception I get is this
[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'Postco'.
But I put a wrong name in there to test what would happen. The code that I am using loops though 4 times so on the first loop it gets the data it needs to retrieve and inserts that to the database the same with the other 2 loops. then it loops though the code again and then finds that there is a column name spelt wrong so it prints out an exception. Just a little more info, the code is inside the loop that loops 4 times if you want to see all of that code you can. But there is a lot and it is quite messy.
Hope this expains a bit more.
Thanks
Boggis
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic