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!

Classpath and Path problems

Status
Not open for further replies.

cmn2

Programmer
Mar 6, 2003
73
0
0
US
Hello, I'm still quite new to Java and could use some help.
I'm trying to connect to a SQL Server database using the Microsoft JDBC driver. I set the CLASSPATH enviornmental variable to...

CLASSPATH=.;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar

Initially I only had the Path variable set, pointing to the bin directory of the JDK and that worked fine for my simple test programs such as HelloWorld. After I added the Classpath variable all my java programs stopped working and are throwing exceptions in main NoClassDefFoundError. If I delete the CLASSPATH variable everything starts working again. Does anyone have any ideas as to what the problem is? I've been working on this for a long time without success. Thank you in advance for your time and help
 
Try specifying the classpath as an argument to the application rather than a system variable. e.g.:
Code:
java -classpath ".;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar"

myenigmaself
"If debugging is the process of removing bugs, then programming must be the process of putting them in." --Dykstra
 
If you have spaces in the directories in your CLASSPATH variable, you must encapsualte them in quotes :

EG :
Instead of :
CLASSPATH=c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;the_rest

CLASSPATH="c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar";the_rest

--------------------------------------------------
Free Database Connection Pooling Software
 
Thanks for respondng myenigmaself and sedj. I do appreciate it. I have gotton past my original problem and now am dealing with a url error, but thats another issue I will work on. I do have a followup question though. Should Path and CLASSPATH be user or system variables? Are there any pitfalls to having one as user and the other as system? Thanks again
 
That really depends on the scope of the application. If you're going to set up the application as a service that will run for all users, they should be system variables. If you're just doing testing on a development box (particularly a box that could have more than one user) you should make them user variables. My guess is that you'll want them to be user variables.

myenigmaself
"If debugging is the process of removing bugs, then programming must be the process of putting them in." --Dykstra
 
The PATH should always be a system variable, because the JDK is/should really be a system wide resource.

CLASSPATH IMO should also be a system variable because some versions of Windows (I'm assuming you are using Windows) have had problems reading CLASSPATH as a user variable.

--------------------------------------------------
Free Database Connection Pooling Software
 
Thanks again myenigmaself and sedj for your input. Its good to know there are programmers like you out there to lend a hand when needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top