Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL statment into a method

 
Ed Carrington
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

"All my attempts dont fetch the last max id"

What DO you get? SQLException maybe?

Herman
 
Vallidevi Appana
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that worked great for me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic