在遗留代码中我有类似的东西..
String q = "select RESULT from usr_dba.CONTEXT where CONTEXT_ID = ?"
Connection dbc = null;
PreparedStatement pst = null;
ResultSet rs = null;
try{
dbc = DataSourceUtils.getConnection(dataSource);
pst = dbc.prepareStatement(q);
pst.setLong(1, id);
rs = pst.executeQuery();
if (rs.next()) {
boolean r = rs.getLong("RESULT");
}...
没什么太疯狂的...... 我想做的是编写测试来覆盖这样的代码。除了我们以前测试的数据库是H2(在内存中,快速),生产中的实际数据库是oracle。问题是我们遇到像“usr_dba”这样的用户组。 H2说语法错误。我想知道是否有通过所有者的方法。
在本地(命名空间)中,我们为H2定义了与oracle匹配的模式。约束,序列等。在H2中唯一不存在的是所有者,因为它是用于测试我们认为我们不需要它。但现在出现这个问题所以我想知道是否也可以在H2添加所有者?当我阅读H2的文档时,我无法找到添加所有者。也许H2不支持它?
编辑: 栈跟踪(添加)
com.att.lpp.prov.util.db.DbException: Database Error: Schema "usr_dba" not found; SQL statement:
select RESULT from usr_dba.CONTEXT where CONTEXT_ID = ?
[90079-160]
at com.line.united.air.db.DBQuery.getAllResult(DBQuery.java:2345)
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:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:85)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:86)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:241)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
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: org.h2.jdbc.JdbcSQLException: Schema "PROV_DBA" not found; SQL statement:
select RESULT from usr_dba.CONTEXT where CONTEXT_ID = ?
[90079-160]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:169)
at org.h2.message.DbException.get(DbException.java:146)
at org.h2.command.Parser.getSchema(Parser.java:613)
at org.h2.command.Parser.getSchema(Parser.java:620)
at org.h2.command.Parser.readTableFilter(Parser.java:1050)
at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1679)
at org.h2.command.Parser.parseSelectSimple(Parser.java:1786)
at org.h2.command.Parser.parseSelectSub(Parser.java:1673)
at org.h2.command.Parser.parseSelectUnion(Parser.java:1518)
at org.h2.command.Parser.parseSelect(Parser.java:1506)
at org.h2.command.Parser.parsePrepared(Parser.java:405)
at org.h2.command.Parser.parse(Parser.java:279)
at org.h2.command.Parser.parse(Parser.java:251)
at org.h2.command.Parser.prepareCommand(Parser.java:217)
at org.h2.engine.Session.prepareLocal(Session.java:415)
at org.h2.engine.Session.prepareCommand(Session.java:364)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1119)
at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:71)
at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:267)
at com.line.united.air.db.DBQuery.getAllResult(DBQuery.java:2345)
... 31 more