aspose file tools*
The moose likes JDBC and the fly likes Error while retrieving column from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Error while retrieving column from database" Watch "Error while retrieving column from database" New topic
Author

Error while retrieving column from database

Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
I have set an attribute named USER, whose values are retrieved through a html, depending upon the user. In this jsp i need to change the password. 't1','t2','t3' are getting old password, new password & confirm password field from html.

First i am checking whether old password field and password column in database has same value.

For updating the password i am retrieving ID no also from the table. (My all tables has ID,username, and password column)

But, while retrieving ID , its showing the error, "Invalid column name". Even the index number (instead of "ID") is not working and showing the error "INVALID COLUMN NUMBER"





kunal
Bharath Raja
Ranch Hand

Joined: Jan 21, 2009
Posts: 111
make sure in your query..



I'm wondering that "you have separate tables for each user". If its not like that, then please check in your query, you have put the user name in the place of table name.Are you sure,"is that right"?


Life is either daring something or nothing - Helen Keller
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Yes, that's right. I am having different tables with "USER's " name.
Error is on Line no.41. (as checked via println statements)
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

1. Your SELECT says : "select password". You're not getting any ID here. Did you want to do something like "select id, password..." ?
2. Are you sure that the name of the table is set in a session attribute called "user" ??


[My Blog]
All roads lead to JavaRanch
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Yes , i am not getting any ID here. I am just checking for same password, If it is found, then i am getting the ID.
Yes, i am sure that the name of the table is set in a session attribute called "user".
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

If it is found, then i am getting the ID.

No, you're not getting the ID. Where's the SELECT clause which retrieves the ID ?
Bharath Raja
Ranch Hand

Joined: Jan 21, 2009
Posts: 111
why can't you change your select query as " select id,password from ... ". then you check your db password to user entered password..
Pawan Kr Gupta
Greenhorn

Joined: Nov 21, 2010
Posts: 26
Yes I agrred with Bharath ,

You should change your query first , then it will work .I think this is not an example of good code because you code could be effected by SQL injection.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

err... why are you establishing a connection through a JSP page ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

I feel the need to post a link to this again Why JDBC + JSP = Bad. Please consider refactoring!


My Blog: Down Home Country Coding with Scott Selikoff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error while retrieving column from database