Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Select single value

 
Bradly Fackrell
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to select a single item rather than a set?



All I want it the max ID. Reading the java.spl package all I see is the option to select a 'set' of data.
 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bradly,
Have you tried to print what there is in ResultSet?
have you tried something like that if you are writing JDBC code in a JSP-


A ResultSet points to its current row of data. Initially the cursor is positioned before the first row. The next method moves the pointer to the next row, and because it returns false when there are no more rows in the ResultSet object.
 
Bradly Fackrell
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ankit. I think that your example is the way to do it. My problem is that right now I can only read. I can't test my code becuse my school's Tomcat server is down.
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know for sure that there will be at most one row in your result set you can replace the "while" with an "if":
If you know for sure there will always be exactly one result, like in this case, you can even skip the if and just call rs.next() once:
 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and welcome to JavaRanch,Bradly..........
 
Bradly Fackrell
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ankit. And thanks to you and Rob for your input.

Right now I'm running with Rob's second suggestions and everthing is working perfect.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic