Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS SQL Server Deriver with Tomcat Problem 1

Status
Not open for further replies.

hughesai

Technical User
Aug 1, 2002
101
0
0
GB
Hi,

I am developing an application which access an MS SQL Server 2000 databse through the MS JDBC driver. My web app is in Tomcat V5.028 on my development PC and 5.025 on the production server.

All is working fine on my development PC so I'm relatively confident that my coding is working, but when I migrate to the production server my web app can't load the JDBC driver. I have loaded the driver .jar files to the common/lib directory. I am using eclipse as my IDE.

I access the server through a network share directly to the tomcat directory - i.e. \\server\tomcat$.
My understanding is that tomcat is installed in "D:\Tomcat\" on the server. On my dev PC it is installed in "c:\tomcat50\".
The MS SQL sever driver is installed in the default directory on both machines - i.e. "C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC". I note that there is one .dll in this directory - I don't think it's needed for connection - it seems to be about creating SQL sps.

I'm sure this is a classpath problem but I can't reconcile it. In eclipse, I have pointed the driver jars to the server rather than my hard disk for their location but that has not helped. I'm unclear how the classpath works between different machines - do I have to change it for every different installation?

I don't know enough about how all this hangs together to find out what is going on - can anyone point me in the right direction?

Thanks.

 
copy the driver jar file to TOMCAT_HOME/common/lib

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Thanks sedj.

No - I've already done that and it has not helped ! ? !

hughesai
 
So do you get a specific error then ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Yes the error is:

Cannot load JDBC driver class
'com.microsoft.jdbc.sqlserver.SQLServerDriver'

hughesai
 
Well, then two possibilities are available :

1) The jar you think contains the driver, actually does not.

2) You have the wrong jar in TOMCAT_HOME/common/lib


--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Thanks Sedj,

Yes - your suggestions seem reasonable.

The driver files I have put in common/lib are:
msbase.jar
mssqlserver.jar
msutil.jar

I have these on my development PC also and I got them from the driver's lib folder after I installed/unpacked it. I have checked all three locations (original driver lib, my dev PC lib, and the server lib) and all three have the same file size and date/time stamps.

I'm therefore pretty sure I've got the right files and in the right location, but I'm lost as to why my app can't seem to find them. I've obviously missed something.

Could this be something more fundamental. Tomcat is running one other application on this server so I'm assuming it's installed and configured correctly (Tech support look after that and I have only limited access to test anything there). Could there be something there that I'm missing and I should ask Tech Support to check?

Thanks,

hughesai
 
One thing you could try is :

If you think those 3 jars are the drivers, and it all works on your dev machines, then delete the files from common/lib, then restart tomcat, and see if you can still connect to the db. If you can, then you are taking the drivers from somewhere else. If you can't then it means those defintely are the driver jars, and the other machine has some other problem.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
sedj

Good thinking - OK I've done that and now I have the same problem on my dev machine, so I have the right files and the app is reading them from the location I thought it was.

I put the files back and the problem didn't go away immediately - I had to re-start Tomcat.

Now Tech Support have told me they restarted Tomcat after installation of the driver - it may be that this did not happen as the users of the other application on the server need high availability - or at least they think they do ;-).

I'm going to see if I can get Tech Support to agree to a restart - this could take 24 hrs - I'll post again with the result.

Thanks for your help and sticking with me on this !

hughesai
 
>>>>> I put the files back and the problem didn't go away immediately - I had to re-start Tomcat.

Tomcat will only load jar files from common/lib on startup - this is expected/normal behaviour.

If you tech support have not restarted Tomcat, then you don't have a hope in hell of it working !

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 

>>>>>>>Tomcat will only load jar files from common/lib on startup - this is expected/normal behaviour.

I didn't know this for sure, but had guessed it probably was the case.

I discussed with Tech Support - they rebooted the server for good measure as well as restarting Tomcat.

My application is now working as well on the server as is is on my dev PC!

Thanks for your help sedj.

hughesai
 
You can also put the jars under WEB-INF/lib in your private directory, these will override those in the common/lib if they exist in both places. Then It is only necessary to restart your application to reload the jars. You may have to ask tech support to do this if you do not have access to the manager/html appliaction.

Jeb Beasley
\0
 
NullTerminator :

Server wide libs such as JDBC drivers really should be put in common/lib, because they are generally static resources, and used by most/all webapps. Also, if you are using a form of pooling, this often is a server-based resource, not a webapp, and if the jars are only in the WEB-INF/lib,then the pooling system would not be able to load the drivers because the ClassLoaders are separate.

Furthermore, whether or not WEB-INF/lib jars override the server's ClassLoader depends entirely on the Tomcat version.

In Tomcat 5, WEB-INF/lib overrides common/lib, but in Tomcat 4, it is the other way round.

It is generally dangerous to put the same signature jars in two places also - I have seen cases in the past where conflicts occur and result in NoClassDefFoundErrors ...

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top