wood burning stoves 2.0*
The moose likes JDBC and the fly likes Invalid column name error 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 "Invalid column name error" Watch "Invalid column name error" New topic
Author

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

try
{
approvedLvlConn = (OracleConnection)getConnection();
approvedOpstmt = (OraclePreparedStatement)
approvedLvlConn.prepareStatement(approvedLevelStr.toString());
approvedSet = approvedOpstmt.executeQuery();
if(approvedSet.next())
maxLevel = approvedSet.getInt(approvedSet.getInt("maxlevel"));
}

Can anyone help. Thanks.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3700
    
    5

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.


My Blog: Down Home Country Coding with Scott Selikoff
Dimit Chadha
Greenhorn

Joined: Jul 05, 2006
Posts: 2
HI
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: http://aspose.com/file-tools
 
subject: Invalid column name error
 
Similar Threads
How to query a certain number of data?
Join condition qucik question
problem with max function (very urgent)
Problem With Sybase XA JDBC 2 Driver and WAS 6
Getting exception on hibernate named query ...