title: Getting ClassNotFoundException on code: "Class.forName("com.microsoft.sqlserver.jdbc.SqlServerDriver");"
body: <p>This is my first <em>Java</em> application and I'm completely inexperienced with <em>Java</em> and <em>NetBeans</em>.  </p>
  
  <p>I have been trying to connect to sql and get some records for 2 days. The problem is about <em>jdbc</em> driver, let me explain. I have downloaded <em>sqljdbc</em> driver and then followed these steps:</p>
  
  <p>Right-click Project->Select Properties->On the left-hand side click Libraries->Under Compile tab - click Add Jar/Folder button and select <em>sqljdbc4.jar</em> file. Then it should be ok, right?</p>
  
  <p>Then I wrote this code But I cant get rid of  this exception: </p>
  
  <pre><code>  Exception in thread "main" java.lang.ClassNotFoundException: 
    com.microsoft.sqlserver.jdbc.SqlServerDriver
  at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:190)
  at javaapplication1.JavaApplication1.main(JavaApplication1.java:30)
  </code></pre>
  
  <p>This is the code </p>
  
  <pre><code>public static void main(String[] args) throws ClassNotFoundException, SQLException {
      String url = "jdbc:sqlserver://.\\SQLEXPRESS;databaseName=Northwind; Integrated Security = SSPI ";
  
      Connection con = null;
      Statement stmt = null;
  
      ResultSet rs = null;
      try {
          Class.forName("com.microsoft.sqlserver.jdbc.SqlServerDriver");
  
          con = DriverManager.getConnection(url);
          String sql = "Select Top 3 from * person.Contact";
          stmt = con.createStatement();
          rs = stmt.executeQuery(sql);
          while (rs.next()) {
              System.out.println(rs.getString(1));
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>