| Author |
SQL statment into a method
|
Ed Carrington
Ranch Hand
Joined: Oct 11, 2007
Posts: 77
|
|
I have a repeated resultset object that I use alot to execute a statement that fetches max id from a table. I was wondering if I can put it in a method and call the method each time I need the max id? The repeated part is: Resultset rs = statement.executeQuery("select max(id) from TableMain"); rs.next(); Here is an example of what I am doing now: I need help on my attempt below because I am not sure how to do it? All my attempts dont fetch the last max id: Call it like this: [ October 11, 2007: Message edited by: Ed Carrington ]
|
 |
Herman Schelti
Ranch Hand
Joined: Jul 17, 2006
Posts: 387
|
|
hi, "All my attempts dont fetch the last max id" What DO you get? SQLException maybe? Herman
|
 |
Vallidevi Appana
Greenhorn
Joined: Jun 30, 2006
Posts: 25
|
|
You can try return id from the method instead of result set. Call this method by passing statment object. Hope this will solve your problem.
|
 |
Ed Carrington
Ranch Hand
Joined: Oct 11, 2007
Posts: 77
|
|
|
Thanks, that worked great for me.
|
 |
 |
|
|
subject: SQL statment into a method
|
|
|