File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Invalid column name error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Invalid column name error" Watch "Invalid column name error" New topic

Invalid column name error

Lalitha Vydyula
Ranch Hand

Joined: Jul 20, 2005
Posts: 69
Hi all,

trying select max(approval_level).. gives java.sql.SQLException: Invalid column name

I have a query like this
select max(approval_level) as maxlevel from fam_quote_header_approval , fam_quote_line_approval where fam_quote_header_approval.header_approval_id = fam_quote_line_approval.header_approval_id and quote_number = 5443 and status = 'Approved'

when I execute the query from SQL prompt its executing fine. but when I execute it from the jdbc it erroring out

approvedLvlConn = (OracleConnection)getConnection();
approvedOpstmt = (OraclePreparedStatement)
approvedSet = approvedOpstmt.executeQuery();
maxLevel = approvedSet.getInt(approvedSet.getInt("maxlevel"));

Can anyone help. Thanks.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3749

Just a thought, but have you tried using table aliases throughout your query such as:

I just guessed which aliases some of the columns belong with. Often times its because of a mismatch or a confusion, using table aliases avoids it.

[OCA 8 Book] [Blog]
Dimit Chadha

Joined: Jul 05, 2006
Posts: 2
It will be better practice to use column numbers instead of column names. This is a tricky solution but it will reduce the error of misspelled column names.
I agree. Here's the link:
subject: Invalid column name error
It's not a secret anymore!