File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes classpath - differences between java command line argument and environment variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "classpath - differences between java command line argument and environment variable" Watch "classpath - differences between java command line argument and environment variable" New topic
Author

classpath - differences between java command line argument and environment variable

Delbert Bell
Greenhorn

Joined: Jul 20, 2005
Posts: 6
I ran into problems using jdbc against a SQL Server db and discovered I need to set the class path to the following:
"C:\Program Files\Microsoft SQL Server 2005 JDBC Driver\sqljdbc_1.0\enu\sqljdbc.jar"

When I create an environment variable CLASSPATH in Windows XP and set it to the path above the program works fine. But setting it via a command line argument to java does not seem to work. Below is the command I'm using.

c:\Projects\java\JDBCtest2>java JdbcTest -CLASSPATH ".;C:\Program Files\Microsoft SQL Server 2005 JDBC Driver\sqljdbc_1.0\enu\sqljdbc.jar"

Does the syntax differ when using the command line or am I doing something else wrong?

Thanks!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi Delbert,

Welcome to JavaRanch!

The -classpath (not -CLASSPATH) switch is an argument to java.exe, not to your program, so it appears on the command line before, not after, your program. Altogether:

java -classpath ".;C:\Program Files\Microsoft SQL Server 2005 JDBC Driver\sqljdbc_1.0\enu\sqljdbc.jar" JdbcTest


[Jess in Action][AskingGoodQuestions]
Richard Anderson
Ranch Hand

Joined: May 20, 2005
Posts: 61

I ran into problems using jdbc against a SQL Server db and discovered I need to set the class path to the following:
"C:\Program Files\Microsoft SQL Server 2005 JDBC Driver\sqljdbc_1.0\enu\sqljdbc.jar"

When I create an environment variable CLASSPATH in Windows XP and set it to the path above the program works fine. But setting it via a command line argument to java does not seem to work. Below is the command I'm using.

c:\Projects\java\JDBCtest2>java JdbcTest -CLASSPATH ".;C:\Program Files\Microsoft SQL Server 2005 JDBC Driver\sqljdbc_1.0\enu\sqljdbc.jar"

Does the syntax differ when using the command line or am I doing something else wrong?

Thanks!


Try this:



-Rich, SCJP 1.4
Delbert Bell
Greenhorn

Joined: Jul 20, 2005
Posts: 6
Wow, now that you point it out it seems painfully obvious. I was getting pretty frustrated. Thanks for the help!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: classpath - differences between java command line argument and environment variable
 
Similar Threads
using classpath when executing a jar
SQL Server 2005 Connectivity issues
no sqljdbc_auth in java.library.path
not able to establish connection for jdbcodbcdriver
Tryin' to create a small MS SQL Java Application