在grails 2.4.3 + groovy 2.3项目中找不到适用于jdbc的驱动程序:jtds:sqlserver [英] No suitable driver found for jdbc:jtds:sqlserver in grails 2.4.3 + groovy 2.3 project

查看:137
本文介绍了在grails 2.4.3 + groovy 2.3项目中找不到适用于jdbc的驱动程序:jtds:sqlserver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的圣杯项目中遇到了一个奇怪的问题,在尝试了很多后,我在这里发布了这个问题。我尝试了所有与URL相关的组合形式 http://jtds.sourceforge.net/faq.html#noSuitableDriver 和其他堆栈溢出答案,如帮我创建一个jTDS连接字符串



grails 2.4.3使用groovy 2.3的项目,并试图使用jtds 1.3.1连接SQL Server数据库,但总是得到没有找到适合jdbc的驱动程序:jtds:sqlserver:但是为了测试这种情况,我编写了独立的程序下面是同样的数据库使用相同的jar jtds 1.3.1及其工作正常。

  try {
Class.forName ( net.sourceforge.jtds.jdbc.Driver);
String url =jdbc:jtds:sqlserver://< hostname>:< port> /< database>;
连接con = DriverManager.getConnection(url,user,password);

Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);}

下面我提供了grails连接类的项目代码片段

 类SQLServerConnection实现DBConnection {

@Override
public Connection getConnection(String serverName,String databaseName){
// TODO自动生成的方法存根
Class.forName(net.sourceforge.jtds.jdbc.Driver);
String url =jdbc:jtds:sqlserver://< host>:< port> /< database>;
连接con = DriverManager.getConnection(url,user,password);
return con


此方法

  def dataFaucetColumn(){
def currentApp = RawDataApp.get(params.int('id')) )
String query =SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='+ currentApp?.tableName +'
Connection con = new SQLServerConnection()。getConnection(currentApp?.servers,currentApp? .databaseName)
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query); }

等待您的答案。

解决方案

以下是如何在利用Hibernate的同时将SQL Server与Grails一起使用:


  1. 打开 grails-app / conf / BuildConfig.groovy

  2. 在依赖项部分添加JTDS依赖项。然后保存该文件。



pre> 依赖关系{
运行时'net.sourceforge.jtds:jtds:1.3.1'

}




  1. 打开 grails-app / conf / DataSource.groovy li>
  2. 在环境部分中,设置数据源并保存文件。在以下示例中,我将为生产环境设置SQL Server。
  3.   environments {
    生产{
    dataSource {
    dbCreate =update
    url = JDBC:JTDS:SQLSERVER://<主机名>:其中端口> /<数据库> 中
    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
    }
    }
    }
    }

    就是这样。现在你可以使用GORM来查询数据库。另外,Hibernate将管理数据库连接:)

    I am facing weird issue in my grail project and after trying a lot i am posting this question here.I have tried all the URL related combination form http://jtds.sourceforge.net/faq.html#noSuitableDriver and other stack over flow answers like Help me create a jTDS connection string.

    I am working on grails 2.4.3 project with groovy 2.3 and trying to connect with SQL Server database using jtds 1.3.1 but always getting "No suitable driver found for jdbc:jtds:sqlserver:" But to test this scenario i have written stand alone program as given below for same data base using same jar jtds 1.3.1 and its working fine.

    try{
                    Class.forName("net.sourceforge.jtds.jdbc.Driver");
                    String url = "jdbc:jtds:sqlserver://<hostname>:<port>/<database>";
                    Connection con = DriverManager.getConnection(url,"user","password");
    
                    Statement stmt = con.createStatement();
                    ResultSet rs = stmt.executeQuery(query);}
    

    Below I have provided the grails project code snippet for connection class

    class SQLServerConnection implements DBConnection {
    
    @Override
    public Connection getConnection(String serverName, String databaseName) {
        // TODO Auto-generated method stub
        Class.forName("net.sourceforge.jtds.jdbc.Driver");
        String url = "jdbc:jtds:sqlserver://<host>:<port>/<database>";
        Connection con = DriverManager.getConnection(url,"user","password"); 
        return con
    
    }
    

    Action form where i am calling this method

    def dataFaucetColumn (){
        def currentApp = RawDataApp.get(params.int('id'))
        String query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='"+currentApp?.tableName +"'"
        Connection con = new SQLServerConnection().getConnection(currentApp?.servers,currentApp?.databaseName)
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(query); }
    

    waiting for your answers.

    解决方案

    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) :)

    这篇关于在grails 2.4.3 + groovy 2.3项目中找不到适用于jdbc的驱动程序:jtds:sqlserver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆