aspose file tools*
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
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Invalid column name error" Watch "Invalid column name error" New topic
Author

Invalid column name error

Dilip kumar
Ranch Hand

Joined: Oct 16, 2000
Posts: 360
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

Joined: Sep 20, 2005
Posts: 381
Date is a reserved SQL keyword and should never be used as the name of a column.
Dilip kumar
Ranch Hand

Joined: Oct 16, 2000
Posts: 360
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
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

There isn't a SalesAmt column in that table description you posted.
Dilip kumar
Ranch Hand

Joined: Oct 16, 2000
Posts: 360
SalesAmt is an alias

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

Thanks
Dilip
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Invalid column name error