title: Connecting Java program to SQL server 2005 using JTDS
body: <p>I have made a java program (on NetBeans IDE 7.0 beta version) and I want to connect it with the database named as school. This database is created on SQL server 2005 in windows authentication mode and by running SQL management express studio as an administrator. I have created the DSN which is named as "mm".Here host name is "monika-pc".But I am getting the errors. Kindly look at my code please. </p>
  
  <pre><code>package javaapplication2;
  
  
  import java.sql.*;
  
  public class JavaApplication2
  {
  public static void main(String args[])
  {
  int i=0;
  try
  {       
  String str="Select fname from students";
          Class.forName("net.sourceforge.jtds.jdbc.Driver");
          Connection con=DriverManager.getConnection("jdbc:jtds:sqlserver://monika-pc/mm");
          System.out.println("Connection open");
          Statement stmt=con.createStatement();
          ResultSet rs=stmt.executeQuery(str);
          System.out.println("fname\t");
          while(i&lt;3)
          {
              rs.next();
              String lname=rs.getString("lname");
              System.out.println(lname);
              i++;
  
          }
              con.close();    
      }
      catch(Exception ex)
      {
          ex.printStackTrace();
      }
  }
  }
  </code></pre>
  
  <p>and I am getting the following errors..</p>
  
  <pre><code>run:
  java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver
  at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
  at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:169)
  at javaapplication2.JavaApplication2.main(JavaApplication2.java:15)
  BUILD SUCCESSFUL (total time: 1 second)
  </code></pre>
  
  <p>Can anyone solve this problem please.Thanks in advance.!</p>