• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get value returned by query

 
Isaac Ferguson
Ranch Hand
Posts: 1046
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have this code, and I want to set into a variable the result of a query.



Any idea, please?

Regards, Isaac
 
Dave Tolls
Ranch Hand
Posts: 2369
25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The execute method returns a ResultSet object.
You need to use the next() method on that (in a while loop if you expect multiple rows) and then you can read that data for that row.

Your second Statement is completely unnecessary.

Also, you need to make sure you close off your resources (ResultSet, PreparedStatement, Connection).
 
Isaac Ferguson
Ranch Hand
Posts: 1046
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes thanks...I remember from old school days
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!