开发者社区> 问答> 正文

奇怪的问题,列名无效:报错

一条select语句,为了效率查询的时候select后面跟的是所有字段,用spring jdbc 查询报了下面的错误

org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [SELECT SCREEN_NAME FROM ND_RAW.RAW_WM_FORUM_AQ_USERINFO  WHERE USER_ID IN ('avm5q3okmix','b89uqh1l_wa','urielpotato') AND DW_ENTITY_SECTION_URN=285841]; nested exception is java.sql.SQLException: 列名无效
	at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:233)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:407)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:456)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:464)
	at com.sdyc.ndetl.service.impl.ForumAqUserinfoService.loadUsers(ForumAqUserinfoService.java:84)
	at com.sdyc.ndetl.reader.ServiceTest.testForumAq(ServiceTest.java:89)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.sql.SQLException: 列名无效
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113)
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:147)
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:209)
	at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3325)
	at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1926)
	at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:1563)
	at com.mchange.v2.c3p0.impl.NewProxyResultSet.getInt(NewProxyResultSet.java:2573)
	at com.sdyc.ndetl.model.mapper.RawWMForumAqUserinfoMapper.mapRow(RawWMForumAqUserinfoMapper.java:35)
	at com.sdyc.ndetl.model.mapper.RawWMForumAqUserinfoMapper.mapRow(RawWMForumAqUserinfoMapper.java:1)
	at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:92)
	at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:1)
	at org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:446)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:396)
	... 32 more
但是我把相同的sql复制到数据库执行成功!而且我把所有的字段换成 * 去用spring jdbc查询,结果又可以查询出来,所以不是列名不对啊,好蛋疼的问题,求大神现身!!!!

展开
收起
kun坤 2020-06-14 06:41:14 676 0
1 条回答
写回答
取消 提交回答
  • 这种问题你贴错误日志没有用,还是把你原来写的SQL贴出来吧,并说明你所使用的数据库及版本。原始SQL不方便贴,就稍微修改下。######问题已经解决了######怎么解决的啊????######因为mapper里面有那个字段,我的sql里面没有,所以无效!######相同问题纠结了俩小时,兄弟帮忙了!

    2020-06-14 06:41:19
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载