This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Extracting a column value from a row Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Extracting a column value from a row" Watch "Extracting a column value from a row" New topic
Author

Extracting a column value from a row

Varnam Aayiram
Ranch Hand

Joined: Dec 23, 2008
Posts: 88
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

Joined: Sep 27, 2007
Posts: 11
executeUpdate .getString(hoursused ) willl extract the required value.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

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


OCUP UML fundamental and ITIL foundation
youtube channel
Jijesh T Das
Greenhorn

Joined: Sep 27, 2007
Posts: 11
Thanks Jan
Varnam Aayiram
Ranch Hand

Joined: Dec 23, 2008
Posts: 88
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

Joined: Dec 20, 2006
Posts: 2491
    
    8

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

Joined: Dec 23, 2008
Posts: 88
most welcome Jan
 
wood burning stoves
 
subject: Extracting a column value from a row
 
Similar Threads
PreparedStatement binding not working properly (Oracle Problem?)
SetNull in a PreparedStatement
using Hibernate with Session Bean
jdbc question
Select query based on userinput