Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Get value returned by query  RSS feed

 
Isaac Ferguson
Ranch Hand
Posts: 1063
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
Rancher
Posts: 2914
36
  • 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: 1063
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes thanks...I remember from old school days
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!