No suitable driver found for jdbc:jtds:sqlserver in grails 2.4.3 + groovy 2.3 project

大城市里の小女人 提交于 2019-12-06 06:14:36

Here's how you can use SQL Server with Grails, while taking advantage of Hibernate:

  1. Open grails-app/conf/BuildConfig.groovy
  2. In the dependencies section add the JTDS dependency. Then save the file.

Example:

dependencies {
    runtime 'net.sourceforge.jtds:jtds:1.3.1'       

}
  1. Open grails-app/conf/DataSource.groovy
  2. In the environments section, set up the data source and save the file. In the following example I'll set up SQL Server for the production environment

Example:

environments {
    production {
         dataSource {
            dbCreate = "update"
            url = "jdbc:jtds:sqlserver://<hostname>:<port>/<database>"
            username = "X"
            password = "X"
            driverClassName = "net.sourceforge.jtds.jdbc.Driver"
            dialect = org.hibernate.dialect.SQLServerDialect
            properties {
                maxActive = 8 
                minEvictableIdleTimeMillis = 1800000
                timeBetweenEvictionRunsMillis = 1800000
                numTestsPerEvictionRun = 3
                testOnBorrow = true
                testWhileIdle = true
                testOnReturn = true
                validationQuery = "SELECT 1"
                validationQueryTimeout = 3
                validationInterval = 15000
               jdbcInterceptors = "ConnectionState"
               defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
             }
         }
     }
}

That's it. Now you can use GORM to query the database. Plus, Hibernate will manage the database connection(s) :)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!