• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

connecting to an MS SQL server

 
rik antropov
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
trying to connect to ms sql server 2005 express edition from a java program.
got the sqljdbc.jar file from microsoft, and put it in the same folder as the java file. i added this jar file to the classpath and used an IDE to compile the java file. compiling was fine, but when i try to run it from the cmd line (windows XP) it gives me this:

java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at UserMS.main(UserMS.java:36)

if i try to use -classpath in the command like java -classpath C:\blah blah
then it throws

Exception in thread "main" java.lang.NoClassDefFoundError: UserMS

in my code, i use Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")

Has anyone gotten anything like this? Any help would be appreciated.

qin_23
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The classpath needs to include the directory where your application is located, so it should probably look like:

java -classpath .;c:\path\to\mssql-driver.jar UserMS

if UserMS.class is in the current directory.
 
rik antropov
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, that worked. thanks ulf.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic