title: Not able to connect MS SQL server 2008 with java
body: <p>I tried to connect java with My MS SQL express, I downloaded the sqljdbc4.jar also</p>
  
  <p>When I don't bother with the CLASSPATH and all and I try to execute my program( even with sqljdbc in </p>
  
  <blockquote>
    <p>C:\Program Files (x86)\Java\jre6\lib</p>
  </blockquote>
  
  <p>I get the following error </p>
  
  <pre><code>java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:169)
      at Connect.getConnection(Connect.java:24)
      at Connect.displayDbProperties(Connect.java:42)
      at Connect.main(Connect.java:78)
  </code></pre>
  
  <p>Error Trace in getConnection() : com.microsoft.jdbc.sqlserver.SQLServerDriver
  Error: No active Connection</p>
  
  <p>But If I try and set the CLASSPATH variable to point to sqljdbc4.jar then ClassNotHoundExcepetion is occurring with identifying my classname.</p>
  
  <p>Need immediate help. kindly respond.</p>
  
  <p>I use Command line mode of invoking it, I tried setting the classpath in the system variables dialog box of windows 7. and when I do that or use set CLASSPATH="C:\temp\sqljdbc4.jar" the jre fails to recogonize the main class of my program and throws </p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: Connect
  Caused by: java.lang.ClassNotFoundException: Connect
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
  </code></pre>
  
  <p>Could not find the main class: Connect.  Program will exit.</p>
  
  <p>So I am at a loss here.</p>