Hello Friends. i have set my environmental variable path of Microsoft JDBC Driver 4.0 as C:\Program Files\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\enu\sqljdbc4.jar and i have also used the url "com.microsoft.sqlserver.jdbc.SQLServerDriver" in my Class.forName(). But still at run time i get the exception java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver. I am using Microsoft sql server 2005 as my database and I am using Textpad4 as the platform to write the code. I have already enabled the TCP/IP protocol of MSSQLSERVER of SQL server configuration manager. Below I am giving the codes:-

1.  import java.sql.DriverManager;
2.  import java.sql.Connection;
3.  import java.sql.PreparedStatement;
4.  import java.sql.Driver;
5.  import java.sql.ResultSet;
6.  public class Example
7.  {
8.      public static void main(String args[])
9.      {
10.         Connection con=null;
11.         try
12.         {
13.             Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
14.             String url="jdbc:microsoft:sqlserver://localhost:1433;databaseName=microleasing;"; 
15.             con=DriverManager.getConnection(url,"sa","*********");
16.             PreparedStatement ps1=con.prepareStatement("select * from login_details");
17.             ResultSet rs1=ps1.executeQuery();
18.             while(rs1.next())
19.             {
20.                 System.out.println("result set is not empty");
21.             }
22.         }
23.         catch(Exception e)
24.         {
25.             System.out.println("Generated exception is "+e);
26.         }
27.     }   
28. }

But i get exception as:-
Generated exception is java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
I will be greatful if anyone will help me come out of this sad. please please plaese help me. I am using jdk "1.6.0_16" version.

4 Years
Discussion Span
Last Post by NormR1

java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver

Where is the definition of the class named in the error message? The JVM can not find it.
Do you have a jar file that contains that class file? The jar file should be on the classpath for the java command so the JVM can find the class.

The PATH environment variable is used by the OS to find commands. It is not used by the java program.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.