我花了很多时间来解决这个问题。我是 GRAILS 和 GROOVY 的初学者。我有名为“tms_dev”的旧版 Oracle 数据库架构。此模式有一些表(例如 checktypes 表)。我也有域类 Checktype 和 ChecktypesController 类 - 由 GRAILS 生成的控制器。
这个类有列表方法:
def列表(整数最大值){
params.max = Math.min(max ?: 10, 100)
[checktypesInstanceList: Checktypes.list(params), checktypesInstanceTotal: Checktypes.count()]
}
我还配置了 Datasource.groovy 文件以使用具有此类内容的 oracle
dataSource {
pooled = true
driverClassName = "oracle.jdbc.OracleDriver"
dialect = "org.hibernate.dialect.Oracle10gDialect"
username = "TMS_DEV"
password = "password"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop','update'
url = "jdbc:oracle:thin:@server_name:1522:sid_name"
}
}
production {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop','update'
url = "jdbc:oracle:thin:@server_name:1522:sid_name"
}
}
我运行我的应用程序。然后单击主页上的“tst7.ChecktypesController”参考。
结果我有例外:
| Error 2012-08-27 14:41:03,469 [http-bio-8080-exec-9] ERROR util.JDBCExceptionReporter - Table "CHECKTYPES" not found; SQL statement:
select * from ( select this_.CHECKTYPECODE as CHECKTYP1_21_0_, this_.active as active21_0_, this_.availabilitychecktype as availabi3_21_0_, this_.checktypecode as checktyp1_21_0_, this_.checktypedescr as checktyp4_21_0_, this_.TARGETTYPECODE as TARGETTY5_21_0_ from CHECKTYPES this_ ) where rownum <= ? [42102-164]
| Error 2012-08-27 14:41:03,547 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver - JdbcSQLException occurred when processing request: [GET] /Tst7/checktypes/list
Table "CHECKTYPES" not found; SQL statement:
select * from ( select this_.CHECKTYPECODE as CHECKTYP1_21_0_, this_.active as active21_0_, this_.availabilitychecktype as availabi3_21_0_, this_.checktypecode as checktyp1_21_0_, this_.checktypedescr as checktyp4_21_0_, this_.TARGETTYPECODE as TARGETTY5_21_0_ from CHECKTYPES this_ ) where rownum <= ? [42102-164]. Stacktrace follows:
Message: Table "CHECKTYPES" not found; SQL statement:
select * from ( select this_.CHECKTYPECODE as CHECKTYP1_21_0_, this_.active as active21_0_, this_.availabilitychecktype as availabi3_21_0_, this_.checktypecode as checktyp1_21_0_, this_.checktypedescr as checktyp4_21_0_, this_.TARGETTYPECODE as TARGETTY5_21_0_ from CHECKTYPES this_ ) where rownum <= ? [42102-164]
Line | Method
->> 329 | getJdbcSQLException in org.h2.message.DbException
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 169 | get in ''
| 146 | get . . . . . . . . . . . in ''
| 4753 | readTableOrView in org.h2.command.Parser
| 1080 | readTableFilter . . . . . in ''
| 1686 | parseSelectSimpleFromPart in ''
| 1793 | parseSelectSimple . . . . in ''
| 1680 | parseSelectSub in ''
| 1523 | parseSelectUnion . . . . in ''
| 1022 | readTableFilter in ''
| 1686 | parseSelectSimpleFromPart in ''
| 1793 | parseSelectSimple in ''
| 1680 | parseSelectSub . . . . . in ''
| 1523 | parseSelectUnion in ''
| 1511 | parseSelect . . . . . . . in ''
| 405 | parsePrepared in ''
| 279 | parse . . . . . . . . . . in ''
| 251 | parse in ''
| 217 | prepareCommand . . . . . in ''
| 415 | prepareLocal in org.h2.engine.Session
| 364 | prepareCommand . . . . . in ''
| 1121 | prepareCommand in org.h2.jdbc.JdbcConnection
| 71 | <init> . . . . . . . . . in org.h2.jdbc.JdbcPreparedStatement
| 267 | prepareStatement in org.h2.jdbc.JdbcConnection
| 281 | prepareStatement . . . . in org.apache.commons.dbcp.DelegatingConnection
| 313 | prepareStatement in org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
| 55 | <init> . . . . . . . . . in grails.orm.PagedResultList
| 45 | list in tst7.ChecktypesController
| 195 | doFilter . . . . . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1110 | runWorker . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . . . . . in java.lang.Thread
然后我尝试在列表方法中创建直接 Oracle 连接
def list(Integer max) {
def sql = Sql.newInstance("jdbc:oracle:thin:@server_name:1522:instance_name", "TMS_DEV",
"password", "oracle.jdbc.driver.OracleDriver")
sql.eachRow("select * from Dbdrivers"){
println it.dbdrivercode
}
}
比我运行应用程序。结果 println it.dbdrivercode - 工作正常(连接工作!!!)。
这个问题最奇怪的是异常是由h2(内存数据库中的H2)类(org.h2.jdbc.JdbcConnection,org.h2.jdbc.JdbcConnection等)产生的。