sql server - No suitable driver found for jdbc:sqlserver -
i realize considered duplicate topic, have followed recommended steps in other topics of same nature no success.
i using ggts 3.6.4
- grails 2.3.0
- jdk1.7.0_80
- groovy compiler level 2.3
- microsoft sql server 2012
i have grails-app authenticates users logging in against ldap server apache shiro , have following code (in shiro generated authcontroller.groovy
) try , store information external database in session. (note: regards usernames, passwords, , database names, i've changed of them here privacy reasons)
def signin = { subject subject = securityutils.getsubject(); string lowercaseusername=params.username.tolowercase(); def authtoken = new usernamepasswordtoken(lowercaseusername, params.password) // support "remember me" if (params.rememberme) { authtoken.rememberme = true } try{ subject.login(authtoken) if (subject.isauthenticated()) { session.username = lowercaseusername // attempting employee id ms sql sql database = sql.newinstance( 'jdbc:sqlserver://myserver;databasename=mydatabase', 'user', 'password', 'com.microsoft.sqlserver.jdbc.sqlserverdriver' ); database.eachrow('select empid table_name username=${session.username}') { row -> session.empid = row.empid } database.close(); def targeturi = params.targeturi ?: "/home" log.info "redirecting '${targeturi}'." redirect(uri: targeturi) } } ... }
however, following error
sqlexception occurred when processing request: [post] /app/auth/signin - parameters: username: user _rememberme: targeturi: password: *** no suitable driver found jdbc:sqlserver://myserver;databasename=mydatabase. stacktrace follows: java.sql.sqlexception: no suitable driver found jdbc:sqlserver://myserver;databasename=mydatabase @ java.sql.drivermanager.getconnection(drivermanager.java:596) @ java.sql.drivermanager.getconnection(drivermanager.java:215) @ app.authcontroller$_closure3.docall(authcontroller.groovy:45) @ grails.plugin.cache.web.filter.pagefragmentcachingfilter.dofilter(pagefragmentcachingfilter.java:200) @ grails.plugin.cache.web.filter.abstractfilter.dofilter(abstractfilter.java:63) @ org.apache.shiro.web.servlet.abstractshirofilter.executechain(abstractshirofilter.java:449) @ org.apache.shiro.web.servlet.abstractshirofilter$1.call(abstractshirofilter.java:365) @ org.apache.shiro.subject.support.subjectcallable.docall(subjectcallable.java:90) @ org.apache.shiro.subject.support.subjectcallable.call(subjectcallable.java:83) @ org.apache.shiro.subject.support.delegatingsubject.execute(delegatingsubject.java:383) @ org.apache.shiro.web.servlet.abstractshirofilter.dofilterinternal(abstractshirofilter.java:362) @ org.apache.shiro.web.servlet.onceperrequestfilter.dofilter(onceperrequestfilter.java:125) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ java.lang.thread.run(thread.java:745)
i have tried following no success:
- added sqljdbc4.jar /app/lib/
- manually added /app/lib/ classpath (via .classpath)
- added sqljdbc4.jar classpath via
properties
>java build path
>add jars
i've tried these variations sqljdbc4.jar, sqljdbc.jar, , sqlserverjdbc.jar , every combo thereof.
i'm stuck. none of fixes i've read on here, or elsewhere, solve error. appreciated!
edit 1: adding class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver")
above newinstance
call produces following errors:
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 @ java.net.urlclassloader$1.run(urlclassloader.java:366) @ java.net.urlclassloader$1.run(urlclassloader.java:355) @ java.net.urlclassloader.findclass(urlclassloader.java:354) @ java.lang.classloader.loadclass(classloader.java:425) @ java.lang.classloader.loadclass(classloader.java:358) @ java.lang.class.forname(class.java:195) @ isec.authcontroller$_closure3.docall(authcontroller.groovy:45) @ grails.plugin.cache.web.filter.pagefragmentcachingfilter.dofilter(pagefragmentcachingfilter.java:200) @ grails.plugin.cache.web.filter.abstractfilter.dofilter(abstractfilter.java:63) @ org.apache.shiro.web.servlet.abstractshirofilter.executechain(abstractshirofilter.java:449) @ org.apache.shiro.web.servlet.abstractshirofilter$1.call(abstractshirofilter.java:365) @ org.apache.shiro.subject.support.subjectcallable.docall(subjectcallable.java:90) @ org.apache.shiro.subject.support.subjectcallable.call(subjectcallable.java:83) @ org.apache.shiro.subject.support.delegatingsubject.execute(delegatingsubject.java:383) @ org.apache.shiro.web.servlet.abstractshirofilter.dofilterinternal(abstractshirofilter.java:362) @ org.apache.shiro.web.servlet.onceperrequestfilter.dofilter(onceperrequestfilter.java:125) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ java.lang.thread.run(thread.java:745)
is step forward, backward, or running in place?
edit 2: ended having change datasource.groovy
this
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 authcontroller.groovy
data access
try{ subject.login(authtoken) if (subject.isauthenticated()) { shirouser currentuser = new shirouser() def targeturi = params.targeturi ?: "/home" log.info "redirecting '${targeturi}'." redirect(uri: targeturi) } }
and have accessed db modified shirouser.groovy
file
class shirouser { static hasmany = [ roles: shirorole, permissions: string ] user_data userdata; static constraints = { } def getusername() { return userdata.username } }
where user_data.groovy
new domain class containing
class user_data { static mapping = { table "mytablename" } ... }
so i'm onto messing methods! not sure why jdbc stuff didn't work out, gorm path i'm taking now.
you need add sqljdbc4.jar /app/lib/ have done.
have tried adding database connection buildconfig.groovy
datasource { dbcreate = "update" // 1 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 sql server configured accept connection on port 1433. disabled default.
Comments
Post a Comment