在给一个数据库访问类写单元测试时,出现了table or view does not exist错误

心三草 2011-11-25 03:16:24
错误完整提示

org.springframework.jdbc.BadSqlGrammarException: SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred while applying a parameter map.
--- Check the MS-RPT-DEV-DETAIL-EFFECT-COUNT-FOR-PAGING-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: ORA-00942: table or view does not exist

at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:220)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:212)
at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject(SqlMapClientTemplate.java:271)
at com.taobao.union.usc.dal.imp.IbatisRptCpsDevDetailEffectImpl.getItems(IbatisRptCpsDevDetailEffectImpl.java:45)
at com.taobao.union.usc.dal.imp.IbatisRptCpsDevDetailEffectImpl.findDevDetailEffect(IbatisRptCpsDevDetailEffectImpl.java:27)
at com.taobao.union.usc.dal.imp.IbatisRptCpsDevDetailEffectImplTest.testFindDevDetailEffect(IbatisRptCpsDevDetailEffectImplTest.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
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: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred while applying a parameter map.
--- Check the MS-RPT-DEV-DETAIL-EFFECT-COUNT-FOR-PAGING-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: ORA-00942: table or view does not exist

at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForObject(MappedStatement.java:120)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:518)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:493)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
at org.springframework.orm.ibatis.SqlMapClientTemplate$1.doInSqlMapClient(SqlMapClientTemplate.java:273)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:209)
... 24 more
Caused by: java.sql.SQLException: ORA-00942: table or view does not exist

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:810)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:850)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1134)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3339)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3445)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:256)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.ibatis.common.jdbc.logging.PreparedStatementLogProxy.invoke(PreparedStatementLogProxy.java:62)
at $Proxy1.execute(Unknown Source)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:185)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
... 30 more


使用ibatIS访问的数据库,在pl/sql里访问那个表没有任何问题。
第一次做,不知道大神们还需要什么代码。
...全文
3927 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
心三草 2012-02-24
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 forgetsam 的回复:]

引用 13 楼 piano7heart 的回复:

你提出的问题很准确。。。
这个问题我已经解决了。。。
是ibatiS自身的问题。。
他在定位数据库的时候,貌似只能定位到ip地址,对服务没有准确定位。
因为每次他注入给我的数据库,都是同一个ip下的另一个数据源。
这是个很蛋疼,但却很考验人的问题。。。
我还要仔细看ibatIS的代码才能确定问题。

ibatis没有这么烂,……
[/Quote]
哥们。。。
够犀利,你虽然没有解决我的问题。。。
但是,看得出,你对ibatis还是很有研究 啊。。
心三草 2012-02-24
  • 打赏
  • 举报
回复
问题得到了解决。。
首先感谢大家的回复。。。

原因是由于spring的问题。。。
由于在我继承的模板里,存在一个默认的数据源,名字就是叫做dataSourse。。。
所以,当我默认用名字作为spring注入的方法时。。。
他就会无论怎样,都把dataSourse弄成默认数据源。。。
无法正确注入。。。
学无止境+ 2012-02-16
  • 打赏
  • 举报
回复
沒看到答案。。。。。。。。。。。。。
xue_cl 2012-02-16
  • 打赏
  • 举报
回复
2012-02-16 20:20:29,125 [JakartaCommonsLoggingImpl.java:27] [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl] DEBUG java.sql.Connection :: {conn-100000} Connection
2012-02-16 20:20:29,188 [JakartaCommonsLoggingImpl.java:27] [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl] DEBUG java.sql.Connection :: {conn-100000} Preparing Statement: select count(t.SUPPLIER_IC_ID) from vendor.vendor_tb_supplier_ic t
2012-02-16 20:20:34,243 [JakartaCommonsLoggingImpl.java:27] [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl] DEBUG java.sql.PreparedStatement :: {pstm-100001} Executing Statement: select count(t.SUPPLIER_IC_ID) from vendor.vendor_tb_supplier_ic t
2012-02-16 20:20:34,243 [JakartaCommonsLoggingImpl.java:27] [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl] DEBUG java.sql.PreparedStatement :: {pstm-100001} Parameters: []
2012-02-16 20:20:34,243 [JakartaCommonsLoggingImpl.java:27] [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl] DEBUG java.sql.PreparedStatement :: {pstm-100001} Types: []
2012-02-16 20:20:42,698 [SupplierServiceImpl.java:176] [com.nfsq.vendorPlatform.supplier.service.impl.SupplierServiceImpl] ERROR com.nfsq.vendorPlatform.supplier.service.impl.SupplierServiceImpl :: org.springframework.jdbc.BadSqlGrammarException: SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in ibatis/sqlmap-supplier.xml.
--- The error occurred while applying a parameter map.
--- Check the supplier.getSupplierIcCount-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: ORA-00942: table or view does not exist
xue_cl 2012-02-16
  • 打赏
  • 举报
回复
还有我丫的参数根本没传 直接 查询一个count(*)的 求解啊
xue_cl 2012-02-16
  • 打赏
  • 举报
回复
帅哥 肿么解决滴啊 我的连接都放到配置文件里面 但是也出现错误
而且查询的是 coun(*) 也出现了 数据库没有该表或视图
forgetsam 2011-11-25
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 piano7heart 的回复:]

你提出的问题很准确。。。
这个问题我已经解决了。。。
是ibatiS自身的问题。。
他在定位数据库的时候,貌似只能定位到ip地址,对服务没有准确定位。
因为每次他注入给我的数据库,都是同一个ip下的另一个数据源。
这是个很蛋疼,但却很考验人的问题。。。
我还要仔细看ibatIS的代码才能确定问题。
[/Quote]
ibatis没有这么烂,它的数据源要么写在自己的sqlmap主文件里,要么在spring的applicationContext.xml里,如果两个都写才会出错。
心三草 2011-11-25
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 forgetsam 的回复:]

你的错误信息是spring内置的ibatis sqlmap的 你给的类JdbcDatabaseTester是哪里的?dbunit?

你先确定你调用的方法用了你的rptdb1=new JdbcDatabaseTester("oracle.jdbc.driver.OracleDriver","jdbc:oracle:thin:@119.42.225.77:1521:rptdb1","alimm……
[/Quote]
你提出的问题很准确。。。
这个问题我已经解决了。。。
是ibatiS自身的问题。。
他在定位数据库的时候,貌似只能定位到ip地址,对服务没有准确定位。
因为每次他注入给我的数据库,都是同一个ip下的另一个数据源。
这是个很蛋疼,但却很考验人的问题。。。
我还要仔细看ibatIS的代码才能确定问题。
心三草 2011-11-25
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 kouyisc 的回复:]

Java code

兄弟,你的参数呢?怎么传进来?替你改了一下。。parameterClass="java.util.HashMap"为传进来的map类型的参数。。。取值的时候直接取第一个就行了
<select id="MS-RPT-DEV-DETAIL-EFFECT-COUNT-FOR-PAGING" parameterClass="java.util.HashMap" resul……
[/Quote]
啊,多谢你了。
我的数据是通过自己定义的数据格式传进来的。。
没有问题。
forgetsam 2011-11-25
  • 打赏
  • 举报
回复
你的错误信息是spring内置的ibatis sqlmap的 你给的类JdbcDatabaseTester是哪里的?dbunit?

你先确定你调用的方法用了你的rptdb1=new JdbcDatabaseTester("oracle.jdbc.driver.OracleDriver","jdbc:oracle:thin:@119.42.225.77:1521:rptdb1","alimm","alimm","ALIMM");

kouyiSC 2011-11-25
  • 打赏
  • 举报
回复

兄弟,你的参数呢?怎么传进来?替你改了一下。。parameterClass="java.util.HashMap"为传进来的map类型的参数。。。取值的时候直接取第一个就行了
<select id="MS-RPT-DEV-DETAIL-EFFECT-COUNT-FOR-PAGING" parameterClass="java.util.HashMap" resultClass="Integer">
select count(*) as value
From
rpt_cps_dev_detail_effect c
where
c.dev_id = #devId#
and c.thedate >= to_date(#sstarttime#,'yyyy-mm-dd')
and c.thedate <= to_date(#sendtime#,'yyyy-mm-dd')
<isNotEmpty prepend="and" property="toolId">
c.tool_id=#toolId#
</isNotEmpty>
</select>

心三草 2011-11-25
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 forgetsam 的回复:]

在pl/sql里访问那个表没有任何问题

PL-SQL 的 用户名 密码

java连接数据库的用户名 密码

报错的<select>标签里的完整语句
[/Quote]
错了,错了,上一个回复错了。

pl-sql的用户名alimm 密码alimm
java数据库连接rptdb1=new JdbcDatabaseTester("oracle.jdbc.driver.OracleDriver","jdbc:oracle:thin:@119.42.225.77:1521:rptdb1","alimm","alimm","ALIMM");


<select id="MS-RPT-DEV-DETAIL-EFFECT-COUNT-FOR-PAGING" resultClass="int">
<![CDATA[
select count(*)
From rpt_cps_dev_detail_effect c
where c.dev_id = #devId#
and c.thedate>=to_date(#sstarttime#,'yyyy-mm-dd')
and c.thedate<=to_date(#sendtime#,'yyyy-mm-dd')
]]>
<dynamic>
<isNotEmpty property="toolId" prepend="and">
c.tool_id=#toolId#
</isNotEmpty>
</dynamic>
</select>

心三草 2011-11-25
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 forgetsam 的回复:]

在pl/sql里访问那个表没有任何问题

PL-SQL 的 用户名 密码

java连接数据库的用户名 密码

报错的<select>标签里的完整语句
[/Quote]
pl-sql的用户名alimm 密码alimm
java数据库连接rptdb1=new JdbcDatabaseTester("oracle.jdbc.driver.OracleDriver","jdbc:oracle:thin:@119.42.225.77:1521:rptdb1","alimm","alimm","ALIMM");


<select id="MS-CPS-DEV-TOOL-COUNT-FOR-PAGING" resultClass="int">
<![CDATA[
select count(*)
From cps_dev_tool c
where c.top_status=1 and (c.status = 1 or c.status=3)
]]>
</select>
心三草 2011-11-25
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 ruogannian 的回复:]

那你数据源配置的账户和你的表的所属账户是一致的么?如果不一致的话,确认你的数据源配置的账户有权限访问你要操作的表
[/Quote]
恩,专门看的,的确是一致的。
forgetsam 2011-11-25
  • 打赏
  • 举报
回复
在pl/sql里访问那个表没有任何问题

PL-SQL 的 用户名 密码

java连接数据库的用户名 密码

报错的<select>标签里的完整语句
若干年 2011-11-25
  • 打赏
  • 举报
回复
那你数据源配置的账户和你的表的所属账户是一致的么?如果不一致的话,确认你的数据源配置的账户有权限访问你要操作的表
心三草 2011-11-25
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ruogannian 的回复:]

是不是配置文件里面指定了用户
[/Quote]
恩,因为这个表的所有者是某个用户,所以配置文件里我指定了这个用户
心三草 2011-11-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 yuerzm 的回复:]

提示说的很明确了。不存在。。。或者是权限问题
[/Quote]
哎,这就是我最纠结的了。。
我找半天也没找到权限哪里有问题。
希望您能说的仔细点。。。
具体的解决方案。
若干年 2011-11-25
  • 打赏
  • 举报
回复
是不是配置文件里面指定了用户
LucEaspe 2011-11-25
  • 打赏
  • 举报
回复
提示说的很明确了。不存在。。。或者是权限问题

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧