This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extracting a column value from a row

 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks...

I need to execute the following sql query and printout the resulting value to the stack trace. The query is as follows:



iduser is a primary key and therefore hoursused is a value from a column in that same row as 'iduser = p0248448'

This is what I did within the doPost method of the servlet:



I am getting this in my stack tace:



the vaue I am expecting is actually the number 6. I suspect it's cos I am printing the object itself, how do I actually print the value? Hope someone can advise. Thanks
 
Jijesh T Das
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
executeUpdate .getString(hoursused ) willl extract the required value.
 
Jan Cumps
Bartender
Posts: 2586
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Jijesh.
Jijesh T Das wrote:executeUpdate .getString(hoursused ) willl extract the required value.
But don't forget to navigate to the first record in the resultset before calling ResultSet.get...()

regards, Jan
 
Jijesh T Das
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jan
 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys...

Thanks for the replies....I am just curious...shouldn't it be executeQuery instead of executeUpdate??. Anyway based on the advise given, I have managed to get it to work. For the benefit of those caught in a simillar predicament as me, I am posting the code below:



Thanks once again guys...
 
Jan Cumps
Bartender
Posts: 2586
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Varnam Aayiram wrote:..shouldn't it be executeQuery instead of executeUpdate...
True. executeUpdate has some additional functionality that you don't need in a select statement (see javadoc for more info, it's related to auto generated keys). It is a proper approach to use executeQuery for select statements.

and thank you for sharing the solution.

Jan
 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
most welcome Jan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic