I already copied the mysql/j connector to the grails-app/lib folder of my grails application. and my DataSource.groovy file looks like this
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = "password"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://localhost:3306/tewhareoteata3test"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
}
but it gives me this error
Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
Driver occurs if there is a disparity between mysql driver class, mysql driver jar version and mysql database version. The java application attempts to load a driver class from the mysql database driver jar. If the driver class is unable to load, the exception Cannot load driver class: com.
jdbc. Driver'. This is deprecated. The new driver class is `com.
Deprecation and Removal Notes The TLSv1 and TLSv1. 1 connection protocols are now deprecated.
In BuildConfig.groovy
add
dependencies {
runtime 'mysql:mysql-connector-java:5.1.16'
}
In fact it may be there already just commented out.
This tells grails to download mysql-connector
and its dependencies.
You'll need to tell Grails which maven repositories to use (also in BuildConfig.groovy
) :
repositories {
grailsPlugins()
grailsHome()
grailsCentral()
mavenCentral()
}
Uncomment
runtime 'mysql:mysql-connector-java:5.1.20'
in BuildConfig.groovy
.
If you want to include jar files without using automatic dependency resolution, you need to put it in the lib
directory in the project root, not grails-app/lib
. The layout should look like this:
|-- grails-app
| |-- conf
| | |-- hibernate
| | `-- spring
| |-- controllers
| |-- domain
| |-- i18n
| |-- services
| |-- taglib
| |-- utils
| `-- views
| `-- layouts
|-- lib <-- jars go here
|-- scripts
|-- src
| |-- groovy
| `-- java
|-- target
|-- test
| |-- integration
| `-- unit
`-- web-app
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With