*
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extracting a column value from a row
 
Similar Threads
SetNull in a PreparedStatement
PreparedStatement binding not working properly (Oracle Problem?)
using Hibernate with Session Bean
jdbc question
Select query based on userinput