【发布时间】:2014-08-05 01:57:40
【问题描述】:
我是 Groovy & Grails 的新手,面临这个问题。我一直在尝试将 mysql 连接到面临以下问题的 GGTS。
GGTS 3.5.1 圣杯 2.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
我的数据源.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}"
请提出建议。提前感谢您的支持。
【问题讨论】: