如何使用intellij IDE连接grails中的mysql数据库

时间:2013-03-23 14:45:01

标签: mysql grails intellij-idea

我是grails和intellij ide的新手。我在intellij运行了一个grails项目,没关系。但是现在我需要使用mysql数据库而不是默认数据库。我不知道该怎么做。据我所知,我已更改了我的数据源类,如下所示>>>

dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
    properties {
        initialSize = 5
        maxActive = 10
        minIdle = 5
        maxIdle = 5
        maxWait = 100000
        validationQuery = "select 1"
        minEvictableIdleTimeMillis = 60000
        timeBetweenEvictionRunsMillis = 60000
    }
}
hibernate {
    cache.use_second_level_cache = false
    cache.use_query_cache = false
    cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}
// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "update" // one of 'create', 'create-drop','update'
            loggingSql = true
            url = "jdbc:mysql://localhost/sbicloud_jan_13"
            username = "root"
            password = "admin"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://192.168.18.12/sbicloud"
            username = "zia"
            password = "zia123321"
        }
    }
    production {
        dataSource {
        }
    }
}

当我运行应用程序时,控制台中出现一些错误,第一个错误发生在>>>

    Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

有人可以帮我这个吗?!这对我很有帮助。

1 个答案:

答案 0 :(得分:5)

或多或少有两种方法:

  1. 修改BuildConfig.groovy,以便您的应用程序使用MySQL。在BuildConfig中有一个名为“dependencies”的块

    dependencies {
         // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
    
         // runtime 'mysql:mysql-connector-java:5.1.20'
     }
    

    取消注释该行:

    // runtime 'mysql:mysql-connector-java:5.1.20'
    

    它将下载依赖项。

  2. 将MySQL JDBC驱动程序放在grails-app / lib目录中... 我之前发布了一篇博客文章,并附有相关说明。 Look here

相关问题