Loading SQL Server JDBC Driver

131 views
Skip to first unread message

Bim

unread,
Apr 4, 2011, 12:24:14 AM4/4/11
to javaloader-dev
Trying to get JL to provide me with the JDBC driver for Microsoft SQL
Server within a ColdFusion 8 installation. Is it just a matter of
dropping in the 'sqljdbc4.jar' file in the folder I'm pointing JL to
load up my *.jar files? Trying to get DBUnit to recognize this JDBC
driver but everytime I pass in the classname
'com.microsoft.jdbc.sqlserver.SQLServerDriver' and
'jdbc:sqlserver://....' connection string to DBUnit, I get the error

'coldfusion.xml.rpc.CFCInvocationException: [java.sql.SQLException :
No suitable driver found for jdbc:sqlserver://....

I have DBUnit loading properly with JL in a Railo environment because
I believe Railo natively uses the
'com.microsoft.jdbc.sqlserver.SQLServerDriver' class so need to
explicitly load in Railo. But now trying to get things working under
Adobe ColdFusion by manually dropping in 'sqljdbc4.jar' file in the
same directly as 'dbunit-2.4.8.jar' but having no luck.

Bim

Mark Mandel

unread,
Apr 4, 2011, 12:30:50 AM4/4/11
to javaloa...@googlegroups.com
Can we see the code are using to load up JavaLoader and dbunit?

Mark
--
E: mark....@gmail.com
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

cf.Objective(ANZ) - Nov 17, 18 - Melbourne Australia
http://www.cfobjective.com.au

Hands-on ColdFusion ORM Training
www.ColdFusionOrmTraining.com

Bim

unread,
Apr 4, 2011, 1:44:25 AM4/4/11
to javaloader-dev
I have a function that attempts to connect to my MSSQL database as so:

<cffunction name="connectToDb" access="public" returntype="void"
hint="I make the actual JDBC connection using the parameters set
by the function 'setDatabaseConnectionParameters()'">

<cfset
this.getJavaLoader().create('java.lang.Class').forName( 'com.microsoft.sqlserver.jdbc.SQLServerDriver' )>
<cfset variables.jdbcConnection =
this.getJavaLoader().create('java.sql.DriverManager').getConnection(variables.dsConnectionUrl,
variables.dsUsername, variables.dsPassword)>
<cfset variables.dbConnection =
this.getJavaLoader().create('org.dbunit.database.DatabaseConnection').init(variables.jdbcConnection)>
</cffunction>

My jar folder that I have JL pointing to, I have the following setup:

/lib
dbunit-2.4.8.jar
sqljdbc4.jar

Attempting to use the java.sql.DriverManager API which I believe
either requires to have the
'com.microsoft.sqlserver.jdbc.SQLServerDriver' in the classpath or do
it at runtime which I attempt to do with <cfset
this.getJavaLoader().create('java.lang.Class').forName( 'com.microsoft.sqlserver.jdbc.SQLServerDriver' )>.

Any ideas?

Mark Mandel

unread,
Apr 4, 2011, 7:24:50 PM4/4/11
to javaloa...@googlegroups.com

Where is the code where you actually create javaloader?

Sent from my mobile device.

Bim

unread,
Apr 4, 2011, 7:33:00 PM4/4/11
to javaloader-dev
I have the following flow:

MyComponent.cfc
==============
<cfset variables.javaLoaderVariable =
"7c9a4fe0-5f13-11e0-80e3-0800200c9a66">
<cfset variables.jarLibraryPath = expandPath('/javaloader/lib')>

<cffunction name="initJavaLoader" access="public" returntype="void"
hint="I initialize server scoped JavaLoader.">

<!--- create server scoped JavaLoader instance to prevent JVM memory
leaks --->
<cfset
createObject( 'component','JavaloaderUtils' ).init( variables.javaLoaderVariable,
variables.jarLibraryPath ) >

</cffunction>

JavaLoaderUtils.cfc
===============
<cfcomponent displayname="JavaLoaderUtils"
hint="I encapsulate utility functions that deals with
JavaLoader.">

<cfset variables.serverJavaLoaderVariable = ''>

<cffunction name="init" access="public" returntype="void"
description="I initialize the JavaLoader library into the server
scope of the CF application. This is needed to avoid a known JVM
memory leak">
<cfargument name="serverJavaLoaderVariable" required="true"
type="string"
hint="The name of the server scoped variable to hold the
JavaLoader instance. Must be unique name across server scope.">
<cfargument name="jarLibraryPath" required="false"
default="#expandPath('/javaloader/lib')#"
hint="I store the full directory path value to the location of
all the needed dependency *.jars.">

<cfset var jarPath = ''>
<cfset var aJars = ArrayNew(1)>
<cfset variables.serverJavaLoaderVariable =
arguments.serverJavaLoaderVariable>

<cfif NOT structkeyexists(server,
variables.serverJavaLoaderVariable)>
<cfdirectory action="list" name="qJars"
directory="#arguments.jarLibraryPath#" filter="*.jar" sort="name asc">
<cfloop query="qJars">
<cfscript>
ArrayAppend(aJars, directory & "/" & name);
</cfscript>
</cfloop>

<cflock
name="#variables.serverJavaLoaderVariable#.server.JavaLoader"
throwontimeout="true" timeout="60">
<cfset server[variables.serverJavaLoaderVariable] =
createObject("component",
"javaloader.JavaLoader").init(loadPaths=aJars,
loadColdFusionClassPath=true)>
</cflock>
</cfif>
</cffunction>

</cfcomponent>

Mark Mandel

unread,
Apr 4, 2011, 7:44:14 PM4/4/11
to javaloa...@googlegroups.com

You are sure the mssql driver is being loaded?

Is the old version of the server scoped javaloader being used?

Also, you've only shown us part of the error. What does the full error look like?

Mark

Sent from my mobile device.

Bim

unread,
Apr 4, 2011, 7:51:41 PM4/4/11
to javaloader-dev
Note sure if the mssql driver - that's what I'm trying to determine.

As far as the full error message, it is what I wrote earlier:
'coldfusion.xml.rpc.CFCInvocationException: [java.sql.SQLException :
No suitable driver found for jdbc:sqlserver://....

The only thing I'm really leaving out is the full jdbc:sqlserver://
url to the database and username/password info. There's nothing after
that. FYI, I'm only seeing this error message from what the MXUnit
plugin is displaying within CF Builder. Haven't looked into how to see
more of the error stack.

Any suggestions on getting you more info or how to go about
troubleshooting more?

Thanks.

Mark Mandel

unread,
Apr 4, 2011, 9:03:32 PM4/4/11
to javaloa...@googlegroups.com
I'd want to see the entire error.

Mark
Reply all
Reply to author
Forward
0 new messages