java执行sql列名无效_java.sql.SQLException:列名无效

姜华翰
2023-12-01

我无法弄清楚为什么我在这里得到“无效的列名”.

我们已经在Oracle中直接尝试了sql的一个变体,并且它工作正常,但是当我使用jdbcTemplate尝试它时,出了点问题.

List alleXmler = jdbcTemplate.query("select p.applicationid, x.datadocumentid, x.datadocumentxml " +

"from CFUSERENGINE51.PROCESSENGINE p " +

"left join CFUSERENGINE51.DATADOCUMENTXML x " +

"on p.processengineguid = x.processengineguid " +

"where x.datadocumentid = 'Disbursment' " +

"and p.phasecacheid = 'Disbursed' ",

(rs, rowNum) -> {

return Dataholder.builder()

.applicationid(rs.getInt("p.applicationid"))

.datadocumentId(rs.getInt("x.datadocumentid"))

.xml(lobHandler.getClobAsString(rs, "x.datadocumentxml"))

.build();

});

适用于Oracle的整个sql是这样的:

select

process.applicationid,

xml.datadocumentid,

xml.datadocumentxml

from CFUSERENGINE51.PROCESSENGINE process

left join CFUSERENGINE51.DATADOCUMENTXML xml

on process.processengineguid = xml. processengineguid

where xml.datadocumentid = 'Disbursment'

and process.phasecacheid = 'Disbursed'

and process.lastupdatetime > sysdate-14

整个堆栈跟踪:

java.lang.reflect.InvocationTargetException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:507)

at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.IllegalStateException: Failed to execute CommandLineRunner

at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:803)

at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:784)

at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:771)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)

at no.gjensidige.bank.datavarehus.kontonrinfridd.Application.main(Application.java:44)

... 6 more

Caused by: org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [select p.applicationid, x.datadocumentid, x.datadocumentxml from CFUSERENGINE51.PROCESSENGINE p left join CFUSERENGINE51.DATADOCUMENTXML x on p.processengineguid = x.processengineguid where x.datadocumentid = 'Disbursment' ]; nested exception is java.sql.SQLException: Invalid column name

at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231)

at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)

at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:419)

at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:474)

at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:484)

at no.gjensidige.bank.datavarehus.kontonrinfridd.Application.run(Application.java:61)

at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:800)

... 12 more

Caused by: 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.getString(GeneratedResultSet.java:1460)

at org.apache.commons.dbcp2.DelegatingResultSet.getString(DelegatingResultSet.java:267)

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)

at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:60)

at org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:463)

at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:408)

... 16 more

 类似资料: