aspose file tools*
The moose likes JDBC and the fly likes Why is this not working? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Why is this not working?" Watch "Why is this not working?" New topic
Author

Why is this not working?

ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
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

Joined: Sep 13, 2002
Posts: 331
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)?


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why is this not working?