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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 18165
    
    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: 18165
    
    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?
 
Don't get me started about those stupid light bulbs.
 
subject: Invalid column name error
 
Similar Threads
date mapping problem in Hibernet
Problem with Pl/Sql function when calling in java
Invalid column name while calling store procedure
Help with CallableStatement
Getting Errror ORA-00904: invalid column name