This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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: 2549
    
  10

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
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: 2549
    
  10

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extracting a column value from a row
 
It's not a secret anymore!