This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am trying to execute the following query on oracle Db. The query doesn't have any errors ,as when I run it outside my java program it runs fine and returns the result.It gives the following message when I try to run it from my java code. The moment I remove the "upper" word it runs fine.
Can some one please let me know what is the problem. Because of this error I am stuck and can't test my code further.
please answer to my question.
The query received from Database Query is SELECT upper(CYCLE_CLOSE_FLAG),ACCESSIBLE_FLAG FROM SALES_RPT WHERE AGENCY_NBR = ? AND RPT_PERIOD_END_DATE = ? 05646222 2004-07-04 The result set is:weblogic.jdbc.wrapper.ResultSet_oracle_jdbc_driver_OracleResul tSetImpl@8b java.sql.SQLException: Invalid column name at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269) at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.j ava:6240) at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl .java:1557) at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:148 2) at weblogic.jdbc.wrapper.ResultSet_oracle_jdbc_driver_OracleResultSetImp l.getString(Unknown Source)
Hmmm, good point. Didn't read your stack trace properly.
The problem is that, now you've applied the UPPER function to the column, the name of the column in the ResultSetMetadata will be different to that defined in your constant.
You can either use rs.getString(1) or find out what the modified name of the (now computed) column is from the ResultSetMetadata (it'll have UPPER in it somewhere; maybe UPPER(CYCLE_CLOSE_FLAG) or UPPER_CYCLE_CLOSE_FLAG at a guess) and adjust the column name string accordingly.