File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invalid column name error

 
Lalitha Vydyula
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Saloon Keeper
Posts: 3896
16
Eclipse IDE Flex Google Web Toolkit
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dimit Chadha
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic