Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未找到适合jdbc的驱动程序:mysql://localhost_Mysql_Grails_Jdbc - Fatal编程技术网

未找到适合jdbc的驱动程序:mysql://localhost

未找到适合jdbc的驱动程序:mysql://localhost,mysql,grails,jdbc,Mysql,Grails,Jdbc,我是Groovy和Grails的新手,面对这个问题。我一直在尝试将mysql连接到GGTS,以解决以下问题 GGTS 3.5.1 Grails2.3.7 Mysql 5.6.19 我在Buildconfig.groovy中添加了依赖项,在.m2存储库中添加了jar 2.尝试在grails app/lib中添加jar 3.试图添加@grab,但遇到错误,没有系统类加载器' 4.我能够在java/eclipse中使用相同的url,并且能够连接。 控制台中显示错误说明 |Environment set

我是Groovy和Grails的新手,面对这个问题。我一直在尝试将mysql连接到GGTS,以解决以下问题

GGTS 3.5.1 Grails2.3.7 Mysql 5.6.19

我在Buildconfig.groovy中添加了依赖项,在.m2存储库中添加了jar 2.尝试在grails app/lib中添加jar 3.试图添加@grab,但遇到错误,没有系统类加载器' 4.我能够在java/eclipse中使用相同的url,并且能够连接。 控制台中显示错误说明

|Environment set to development
.................................
|Packaging Grails application
........................................
|Running Grails application
|Server running. Browse to http://localhost:8080/Hello
....Error 
|
2014-06-15 00:28:44,903 [http-bio-8080-exec-7] ERROR errors.GrailsExceptionResolver  - SQLException occurred when processing request: [GET] /Hello/book/index
No suitable driver found for jdbc:mysql://localhost/ot. Stacktrace follows:
Message: No suitable driver found for jdbc:mysql://localhost/ot
    Line | Method
->>  596 | getConnection in java.sql.DriverManager
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    215 | getConnection in     ''
|     12 | index . . . . in hello.BookController
|    200 | doFilter      in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter . .  in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker     in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run           in java.lang.Thread
我的datasource.groovy

dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    dialect = 'org.hibernate.dialect.MySQL5InnoDBDialect'

}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
//    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
    cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
}

// environment specific settings
environments {
    development {
        dataSource {
            username = "root"
            password = "lenovo"
            dbCreate = "update"
            url = "jdbc:mysql://localhost/ot"

        }
    }
Buildconfig.groovy

dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime',     'test' or 'provided' scopes e.g.
            runtime 'mysql:mysql-connector-java:5.1.30'
          // runtime 'org.postgresql:postgresql:9.3-1100-jdbc41'
         }
控制器

def index() {

conn = Sql.newInstance("jdbc:mysql://localhost/ot",
                      "root",
                      "lenovo",
                      "com.mysql.jdbc.Driver")
                    //  "org.gjt.mm.mysql.Driver")

conn.rows('select NAME, ROLLNO from student').each{ 
    println "${it.NAME} ${it.ROLLNO}"

请建议。提前感谢您的支持。

错误明确地告诉您需要将mysql JDBC连接器JAR添加到类路径中


它是可用的。

可能不同的类加载器加载JAR,并且在控制器中使用不同的类加载器。正如这里所建议的:从注入的数据源而不是Sql.newInstance创建Sql实例

仍然应该考虑定义域类并使用GORM.

访问数据库。 希望这有帮助,
droggo

Jar出现在下面的文件夹中1.m2 repository 2.groovy/lib 3 grails app/lib…我也可以在我的项目/properties/java Buildpath中看到这个Jar…非常感谢,我尝试了使用GORM DSL,并且我能够将数据保存到表中。下面是我所做的更改,1因为它是一个现有表,我使用了静态映射GORM DSL..2在Datasource.groovy 3中使用了dbCreate=Update而不是groovy sql语句,我在GORM语句下面使用了'def stud=new Employee''stud.seqNum=1''stud saveflush:true,failOnError:true“def findstudent=Employee.list”我仍然无法理解groovy sql语句不起作用的原因。如果我得到答案,我会更新…您可以使用直接sql,只需基于数据源创建sql实例。如果需要创建不带数据源的sql实例,请通过如下方式指定类加载器加载它:def driver=Class.forNamedriverClassName,false,this.Class.classloader.newInstance;def属性=新属性;setProperty'user',用户名;设置属性“密码”,密码;driver.connectdbUrl,属性;通过这种方式,您可以指定应该使用哪些类加载器,哪些类加载器可以访问JDBClibloader。我尝试使用dataSource而不是sql.newInstance。它正在工作。现在我可以使用GroovySQL显示记录了。我想分享我观察到的:“def dataSource”不应该在方法内部,而应该在类级别。那么,似乎只有groovy才会注入。当然,数据源应该有正确的属性。再次感谢。@user3582387嗨,我也面临同样的问题。你能在这里分享正确的代码吗。