Grails:SQLException:没有为jdbc找到合适的驱动程序:oracle:thin

时间:2014-11-26 11:42:16

标签: oracle grails

当我使用Grails 2.4.3在GGTS 3.6.2中运行我的应用程序时,我收到了一条消息:

Caused by SQLException: No suitable driver found for jdbc:oracle:thin:@server:port/OCI
->>  689 | getConnection in java.sql.DriverManager
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    247 | getConnection in     ''
|     18 | <init> .  in awtool.Controller
|    266 | run       in java.util.concurrent.FutureTask
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . in java.lang.Thread
Error |
Forked Grails VM exited with errorJava HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0

我阅读了很多关于此错误的帖子,并使用了一些建议。 我将ojdbc6.jar添加到project / lib 我还使用Add External JAR在项目Java Build Path中添加了ojdbc6.jar ..

Java和Grails PATH正常

我有办法解决这个问题吗?

BuildConfig.groovy:

grails.servlet.version = "3.0" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.work.dir = "target/work"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"

grails.project.fork = [
    // configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
    compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],

    // configure settings for the test-app JVM, uses the daemon by default
    // test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
    // configure settings for the run-app JVM
    run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
    // configure settings for the run-war JVM
    war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
    // configure settings for the Console UI JVM
    console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]

grails.project.dependency.resolver = "maven" // or ivymaven
grails.project.dependency.resolution = {
    // inherit Grails' default dependencies
    inherits("global") {
        // specify dependency exclusions here; for example, uncomment this to disable ehcache:
        // excludes 'ehcache'
    }
    log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    checksums true // Whether to verify checksums on resolve
    legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility

    repositories {
        inherits true // Whether to inherit repository definitions from plugins

        grailsPlugins()
        grailsHome()
        mavenLocal()
        grailsCentral()
        mavenCentral()
        // uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
        // mavenRepo "http://repository.codehaus.org"
        // mavenRepo "http://download.java.net/maven/2/"
        // mavenRepo "http://repository.jboss.com/maven2/"
    mavenRepo "http://repo.spring.io/milestone/"
    }

    dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
        runtime 'mysql:mysql-connector-java:5.1.34'
        // runtime "com.oracle:ojdbc6:11.2.0.4"
        // runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
        test "org.grails:grails-datastore-test-support:1.0-grails-2.4"
    }

    plugins {
        // plugins for the build system only
        build ":tomcat:7.0.55"

        // plugins for the compile step
        compile ":scaffolding:2.1.2"
        compile ':cache:1.1.7'
        compile ":asset-pipeline:1.9.6"
    compile ":spring-security-core:2.0-RC4"
    compile ":spring-security-ldap:2.0-RC2" 
    compile ":force-ssl:1.0.0"
        // plugins needed at runtime but not for compilation
        runtime ":hibernate4:4.3.5.5" // or ":hibernate:3.6.10.17"
        runtime ":database-migration:1.4.0"
        runtime ":jquery:1.11.1"

        // Uncomment these to enable additional asset-pipeline capabilities
        //compile ":sass-asset-pipeline:1.9.0"
        //compile ":less-asset-pipeline:1.10.0"
        //compile ":coffee-asset-pipeline:1.8.0"
        //compile ":handlebars-asset-pipeline:1.3.0.3"
    }
}


grails.server.port.http=8088

DataSource.groovy中

import groovy.sql.*

dataSource {
    pooled = true
    dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
    driverClassName = "com.mysql.jdbc.Driver"
    username = "login"
    password = "pass"
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory'
}
// environment specific settings
environments {
    development {
        dataSource {

            dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:mysql://server:port/login"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://server:port/login"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://server:port/login"

        }
    }
}

2 个答案:

答案 0 :(得分:1)

除了Burt的答案解释如何让Grails找到您的Oracle库之外,您还需要更改DataSource.groovy以连接到Oracle数据库(它当前为MySQL配置)。您需要将其更改为:

dataSource {
    pooled = true
    driverClassName = "oracle.jdbc.driver.OracleDriver"
    dialect = "org.hibernate.dialect.Oracle10gDialect"
    dbCreate = "update" 
    url = 'jdbc:oracle:thin:@localhost:1521:mydb'
    username = "root"
    password = "password"
    properties {
        // See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
        jmxEnabled = false
        initialSize = 5
        maxActive = 50
        minIdle = 5
        maxIdle = 25
        maxWait = 10000
        maxAge = 10 * 60000
        timeBetweenEvictionRunsMillis = 5000
        minEvictableIdleTimeMillis = 60000
        validationQuery = "select 1 from dual"
        validationQueryTimeout = 3
        validationInterval = 15000
        testOnBorrow = true
        testWhileIdle = true
        testOnReturn = false
        jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
        defaultTransactionIsolation = Connection.TRANSACTION_READ_COMMITTED
    }
}
hibernate {
    flush.mode = 'manual'

    cache.use_second_level_cache = true
    cache.use_query_cache = true
    cache.region.factory_class = "net.sf.ehcache.hibernate.EhCacheRegionFactory"
}

mydbrootpassword替换为您的架构名称,以及您用来访问它的用户名和密码。

答案 1 :(得分:0)

“添加外部JAR ..”以及添加到IDE类路径的其他方法在使用Grails时没有用 - IDE从Grails依赖项构建其类路径,因此您只需要确保Grails可以访问。

当向lib目录添加jar时(通常应该避免这种情况,但在这种情况下需要,因为Oracle恼人地拒绝将他们的驱动程序放在公共存储库中)你需要运行

 grails compile --refresh-dependencies

将它添加到类路径中 - Grails没有在/lib中暂时自动检测jar。

一旦你这样做,如果你需要jar进行编译(在这种情况下你不需要),那么从Grails刷新IDE。在GGTS / STS中,您可以通过右键单击左侧树中的项目根节点并选择Grails Tools |来实现此目的。刷新依赖关系。