Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invalid column name error

 
Dilip kumar
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All -

Can anyone tell me what I'm doing wrong here. Appreciate any help. Thanks

In DB

CREATE OR REPLACE FUNCTION sf_Sales (
Date VARCHAR2,
Company_ID VARCHAR2
) RETURN NUMBER IS
:
:
:

In Java Code

sqlStr = "SELECT sf_Sales(" + sqlParam + ") SalesAmt from dual";
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection("jdbc racle:thin:@<IP>:<Port>:<sid>","Admin","Password");
Statement statement = connection.createStatement();
selcurs = statement.executeQuery(sqlStr);
selcurs.next()
System.out.println(selcurs.getFloat("SalesAmt")); <-- Getting invalid column name error.
[ November 15, 2005: Message edited by: Dilip kumar ]
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Date is a reserved SQL keyword and should never be used as the name of a column.
 
Dilip kumar
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response.

I did correct the varibale name in the DB but forgot to update the code I pasted here. Still I'm getting same error. It looks like the java code is not recognizing alias. Don't know why.
 
Paul Clapham
Sheriff
Pie
Posts: 20771
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't a SalesAmt column in that table description you posted.
 
Dilip kumar
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SalesAmt is an alias

sqlStr = "SELECT sf_Sales(" + sqlParam + ") SalesAmt from dual";

Thanks
Dilip
 
Paul Clapham
Sheriff
Pie
Posts: 20771
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That isn't SQL you posted, it's Java. The result of executing it is the SQL which is the problem. Why don't you look at it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic