aspose file tools*
The moose likes JDBC and the fly likes Select max id and calling method from another class 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 "Select max id and calling method from another class" Watch "Select max id and calling method from another class" New topic
Author

Select max id and calling method from another class

Joseph Smithern
Ranch Hand

Joined: Feb 11, 2006
Posts: 89
I have a method that has a prepared statement that executes before a SQL select max id query. The Prepared statement works great where I call it in another method in my Java Helper Class file.

Now I want to move the method with the prepared statement into another class and call in in my Java Helper Class.

For some reason it didnt work. Here is what it looked like with both methods in one class and everything working great with my Access 2003 database where the prepared statement runs and then I get the max id from the table:



Now if I put the insertData method in another class and call it in the HelperDB class it will correctly insert data into tableone but it doesnt retrieve the correct max tableoneid value.





It seems like the the object new AnotherHelper().insertData(user) runs after the select max sql statement (select max(tableoneId) from tableone) because I always get the second to last max value from tableone. Please advise.
[ October 02, 2007: Message edited by: Joseph Smithern ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Select max id and calling method from another class