java.sql.SQLException: Invalid column name
The problem isn't the query. The query is running fine.
The problem is in the row-mapping that converts a row from the ResultSet
into a domain object. It seems that as part of the row-mapping in your application you are trying to read out of the ResultSet
a value from a column that it doesn't contain.
The key lines of your stacktrace are the following three, near the bottom:
at org.apache.commons.dbcp2.DelegatingResultSet.getString(DelegatingResultSet.java:267)
at no.gjensidige.bank.datavarehus.kontonrinfridd.Application.lambda$run$0(Application.java:69)
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:93)
The middle of these three lines would appear to be in your code. Line 69 of your Application
class contains a lambda which is calling ResultSet.getString()
, but as this results in an 'Invalid column name' error, then (a) you are passing a string for a column name rather than a numeric column index, and (b) the column name you're passing in doesn't exist in the result set.
Now that you've edited your question to include the call to jdbcTemplate.query()
, and in particular the lambda responsible for mapping a result-set row to an object, the problem is a little clearer. When calling rs.getInt(...)
or rs.getString(...)
with column names as opposed to indexes, don't include prefixes such as p.
or x.
. Instead of writing rs.getInt("p.applicationid")
or rs.getInt("x.datadocumentid")
, write rs.getInt("applicationid")
or rs.getInt("datadocumentid")
.
java.sql.SQLException: Invalid column name at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:4146) at oracle.jdbc.driver.InsensitiveScrollableResultSet.findColumn(InsensitiveScrollableResultSet.java:300) at oracle.jdbc.driver.GeneratedResultSet.getInt(GeneratedResultSet.java:1350) at com.zaxxer.hikari.pool.HikariProxyResultSet.getInt(HikariProxyResultSet.java)
The issue also occurs when the index_name you are trying to fetch from Resultset is not present, please check your query once and match with the column index name that you are trying to fetch from ResultSet. This can be on the possibility of this cause.