简体   繁体   English

找不到适用于jdbc:sqlserver的驱动程序

[英]No suitable driver found for jdbc:sqlserver

I realize this is what would be considered a duplicate topic, but I have followed the recommended steps in the other topics of this same nature with no success. 我意识到这是一个重复的主题,但是在其他相同主题的主题中,我遵循了推荐的步骤,但没有成功。

I am using GGTS 3.6.4 with 我正在使用GGTS 3.6.4

  • Grails 2.3.0 Grails 2.3.0
  • jdk1.7.0_80 jdk1.7.0_80
  • Groovy compiler level 2.3 Groovy编译器级别2.3
  • Microsoft SQL Server 2012 Microsoft SQL Server 2012

I have a grails-app which authenticates users logging in against an LDAP server with Apache Shiro and I have the following code (in the Shiro generated AuthController.groovy ) to try and store some information from an external database in the session. 我有一个grails-app,它使用Apache Shiro对通过LDAP服务器登录的用户进行身份验证,并且我有以下代码(在Shiro生成的AuthController.groovy )尝试在会话中存储来自外部数据库的某些信息。 (Note: With regards to usernames, passwords, and database names, I've changed all of them here for privacy reasons) (注意:关于用户名,密码和数据库名称,出于隐私原因,我在此处更改了所有名称)

def signIn = {
    Subject subject = SecurityUtils.getSubject();
    String lowerCaseUserName=params.username.toLowerCase();
    def authToken = new UsernamePasswordToken(lowerCaseUserName, params.password)

    // Support for "remember me"
    if (params.rememberMe) {
        authToken.rememberMe = true
    }

    try{
        subject.login(authToken)

        if (subject.isAuthenticated()) 
        {
            session.username = lowerCaseUserName

            // Attempting to get employee id from MS SQL
            Sql Database = Sql.newInstance(
                'jdbc:sqlserver://myserver;DatabaseName=mydatabase',
                'user',
                'password',
                'com.microsoft.sqlserver.jdbc.SQLServerDriver'
            );
            Database.eachRow('select empid from table_name where username=${session.username}') { row ->
                session.empid = row.empid
            }
            Database.close();   

            def targetUri = params.targetUri ?: "/home"
            log.info "Redirecting to '${targetUri}'."
            redirect(uri: targetUri)
        }
    }
    ...
}

However, I get the following error 但是,出现以下错误

SQLException occurred when processing request: [POST] /app/auth/signIn - parameters:
username: user
_rememberMe: 
targetUri: 
password: ***
No suitable driver found for jdbc:sqlserver://myserver;DatabaseName=mydatabase. Stacktrace follows:
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://myserver;DatabaseName=mydatabase
at java.sql.DriverManager.getConnection(DriverManager.java:596)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at app.AuthController$_closure3.doCall(AuthController.groovy:45)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

I have tried the following with no success: 我尝试了以下方法,但均未成功:

  • Added sqljdbc4.jar to /app/lib/ 将sqljdbc4.jar添加到/ app / lib /
  • Manually added /app/lib/ to classpath (via .classpath) 手动将/ app / lib /添加到类路径(通过.classpath)
  • Added sqljdbc4.jar to the classpath via the Properties > Java Build Path > Add JARs 通过Properties > Java Build Path > Add JARs将sqljdbc4.jar添加到类Java Build Path

I've tried these variations with sqljdbc4.jar, sqljdbc.jar, and sqlserverjdbc.jar and every combo thereof. 我已经使用sqljdbc4.jar,sqljdbc.jar和sqlserverjdbc.jar及其所有组合尝试了这些变体。

I'm basically stuck. 我基本上卡住了。 None of the fixes I've read on here, or elsewhere, solve my error. 我在这里或其他地方读过的所有修复程序都无法解决我的错误。 Any help would be greatly appreciated! 任何帮助将不胜感激!

Edit 1: Adding Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver") above the newInstance call produces the following errors: 编辑1:在newInstance调用上方添加Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")会产生以下错误:

ClassNotFoundException occurred when processing request: [POST] /app/auth/signIn - parameters:
username: user
_rememberMe: 
targetUri: 
password: ***
com.microsoft.sqlserver.jdbc.SQLServerDriver. Stacktrace follows:
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName(Class.java:195)
at isec.AuthController$_closure3.doCall(AuthController.groovy:45)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

Is this a step forward, backward, or are we running in place? 这是向前,向后迈出的一步,还是我们已经到位?

Edit 2: What I ended up having to do was change my DataSource.groovy to this 编辑2:我最后要做的就是将DataSource.groovy更改为此

dataSource {
    pooled = true
}
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 {
            dbCreate = "validate"
            url = "jdbc:sqlserver://myserver:1433;databaseName=mydatabase;"
            driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
            username = "myusername"
            password = "mypassword"
        }
    }
....
}

and changed my AuthController.groovy data access to 并将我的AuthController.groovy数据访问权限更改为

    try{
        subject.login(authToken)
        if (subject.isAuthenticated()) 
        {
            ShiroUser currentUser = new ShiroUser()

            def targetUri = params.targetUri ?: "/home"
            log.info "Redirecting to '${targetUri}'."
            redirect(uri: targetUri)
        }
    }

and I have successfully accessed my DB with a modified ShiroUser.groovy file 并且我已经使用修改后的ShiroUser.groovy文件成功访问了我的数据库

class ShiroUser {

    static hasMany = [ roles: ShiroRole, permissions: String ]

    User_Data userData;

    static constraints = {
    }

    def getUsername() {
        return userData.username
    }
}

where User_Data.groovy is a new domain class containing 其中User_Data.groovy是一个新的域类,其中包含

class User_Data {

    static mapping = {
        table "mytablename"
    }
    ...
}

So now I'm onto messing with methods! 所以现在我要弄乱方法! Not sure why JDBC stuff didn't work out, but GORM is the path I'm taking now. 不知道为什么JDBC的东西不能解决,但是GORM是我现在要走的道路。

you definitely need to add sqljdbc4.jar to /app/lib/ which you have already done. 您肯定需要将sqljdbc4.jar添加到/ app / lib /中。

have you tried adding database connection to the BuildConfig.groovy 您是否尝试过将数据库连接添加到BuildConfig.groovy

dataSource {
        dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
        driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
        dialect = "org.hibernate.dialect.SQLServerDialect"
        url = "jdbc:sqlserver://localhost:1433;databaseName=dbName"
        username = "sa"
        password = ""
    }

Also make sure the SQL server is configured to accept connection on port 1433. It is disabled by default. 另外,还要确保将SQL Server配置为接受端口1433上的连接。默认情况下它被禁用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “找不到适用于jdbc:microsoft:sqlserver的驱动程序” - “No suitable driver found for jdbc:microsoft:sqlserver” 在Spring框架中找不到适用于jdbc:sqlserver的驱动程序 - No suitable driver found for jdbc:sqlserver in Spring framework Java EE-找不到适用于jdbc:sqlserver的驱动程序 - Java EE - No suitable driver found for jdbc:sqlserver 找不到适用于jdbc:sqlserver:// repcode; DatabaseName = reporting的驱动程序 - No suitable driver found for jdbc:sqlserver://repcode;DatabaseName=reporting java.sql.SQLException:找不到适用于jdbc:sqlserver的驱动程序: - java.sql.SQLException: No suitable driver found for jdbc:sqlserver: 没有找到适合 jdbc:sqlserver:ex;databaseName=Cities_names 的驱动程序 - No suitable driver found for jdbc:sqlserver:ex;databaseName=Cities_names 修复 Java db 连接到 sqlserver 中的“找不到适合 jdbc 的驱动程序”错误 - Fix 'No suitable driver found for jdbc' error in Java db connection to sqlserver java.sql.SQLException:没有找到适合 jdbc:microsoft:sqlserver 的驱动程序 - java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver 错误:java.sql.SQLException:未找到适合jdbc:sqlserver的驱动程序 - Error: java.sql.SQLException: No suitable driver found for jdbc:sqlserver Docker 找不到合适的驱动程序 sqlserver - Docker no suitable driver found sqlserver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM