class getDBConnection { public static void main (String [] args) { try { Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); } catch(ClassNotFoundException cnfe) { System.out.println("Class Not Found Exception:"); System.out.println(cnfe); } } }
I have downloaded the Microsoft SQL Server 2000 Driver for JDBC and its in the default location of C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC
I have also set my CLASSPATH to the following C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib
My class compiles just fine, but when I run it, I get: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
As a genuine java greenhorn, I'd appreciate some advice on why this is happening and how to correct it.
THANKS!
Ivor Lithan
Greenhorn
Joined: May 30, 2004
Posts: 10
posted
0
You need to move the jar files (msbase.jar, mssqlserver.jar, msutil.jar) from the lib directory of the default install location of the drivers, i.e. C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib - into your class path, somewhere along the way. Your class compiles fine because you don't actually reference the sql driver until run time.
Dan Mortimer
Greenhorn
Joined: Jun 01, 2004
Posts: 18
posted
0
Hi Ivor,
Thanks for responding...
My CLASSPATH system variable is set to: C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib
If I need to move the .jar files that appear in this directory by default, I'm not sure where I need to put them. Please can you help...
Thanks!
Ivor Lithan
Greenhorn
Joined: May 30, 2004
Posts: 10
posted
0
I have also set my CLASSPATH to the following C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib
Oops I completly missed that bit. My bad.
the only thing I can think of, off the top of my head right now, is the spaces in the file path. try moving the jars somewhere where you have no spaces in the path i.e. c:\lib or something?
Dan Mortimer
Greenhorn
Joined: Jun 01, 2004
Posts: 18
posted
0
Hi Ivor,
I copied the three jar files to: C:\SQLServerDriver\lib
Then, I updated CLASSPATH system variable to: C:\SQLServerDriver\lib;
Then, I rebooted my machine, but I am still getting the same problem. I'm running on Windows XP, with jdk v1.4.2_03 if this makes any difference...
Any suggestions gratefully received...
Thanks
Ivor Lithan
Greenhorn
Joined: May 30, 2004
Posts: 10
posted
0
ok - level of desperation time - add the jars explicitly to your class path, i.e :
C:\SQLServerDriver\lib\sqlserver.jar;C:\SQLServerDriver\lib\msutil.jar and so on
Assumimg you are running this from the command line, echo %CLASSPATH% and make sure it is what you think it is. Then make sure you have all the MSSQL driver jars in the CLASSPATH (there's a utils.jar too I think). Also make sure you are running the app with the classpath you think you are - which is easy from the command line, with the classpath argument - but can be less clear with IDE which might be using their own CLASSPATH. If all of the above is OK, then the class will be found.
As Paul stated above be absolutely sure your classpath is set correctly. Also your command line should be like:
Be sure to include the "." seperated by ";" somewhere in your classpath, this will tell the compiler to look in the current working directory as well as the CLASSPATH environment variable, otherwise you will get a message similar to
Great News! It seems to be working now. To get this far, I set my ClASSPATH variable as advised and checked it was correct at the command line as follows:
Having done this, the class compiles and runs just fine. Just for my own morbid curiosity, can you briefly explain what the ".;" actually means in the classpath? What is my current working directory?
Thanks to you all for assisting me!
Craig Jackson
Ranch Hand
Joined: Mar 19, 2002
Posts: 405
posted
0
Well if I remember correctly, the "." and the ".." are DOS and UNIX symbols that refer to the CURRENT and PARENT directory respectfully.
For example in DOS: # Copying Test.java from c:\temp to current directory
is the same is
# Move up to the Parent Directory
I think you get the idea.
Craig.
Craig Jackson
Ranch Hand
Joined: Mar 19, 2002
Posts: 405
posted
0
Correction:
Okay I'm done with the DOS and UNIX lessons.
Back to JAVA.
Craig.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: How to establish JDBC Connection to SQL Server