我是Groovy&的新手Grails,面临这个问题。我一直在尝试将mysql连接到GGTS面临以下问题。
GGTS 3.5.1 Grails 2.3.7 Mysql 5.6.19
控制台中显示的错误说明
|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}"
请建议。感谢您的支持。
答案 0 :(得分:0)
该错误明确告诉您需要将mysql
JDBC连接器JAR添加到类路径中。
可以使用here。
答案 1 :(得分:0)
可能不同的类加载器加载jar并且在控制器中使用不同的类。正如这里提出的:Grails sql queries从注入的dataSource而不是Sql.newInstance()创建Sql实例
你仍然应该考虑定义一个Domain类并使用GORM访问数据库。
希望这有帮助, droggo