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


If you are seeing this exception while trying to use the SQL Server 2005 JDBC driver, then you will need to update the application.


The class name has changed between the SQL Server 2000 JDBC driver and the SQL Server 2005 JDBC driver.  This particular class “com.microsoft.jdbc.sqlserver.SQLServerDriver” is the class name for the SQL Server 2000 JDBC driver.  The SQL Server 2005 JDBC driver class name is “com.microsoft.sqlserver.jdbc.SQLServerDriver“.
Note the change: from “microsoft.jdbc.sqlserver” to “microsoft.sqlserver.jdbc”


In addition, the SQL Server 2005 JDBC driver has a different URL prefix from the SQL Server 2000 JDBC driver.  The SQL Server 2000 JDBC driver uses an URL prefix of “jdbc:microsoft:sqlserver://”, while the SQL Server 2005 JDBC driver uses an URL prefix of “jdbc:sqlserver://“.
Note the removal of “microsoft” from the URL prefix.


For additional information on all the different Connection string properties, please refer to the following MSDN topic: http://msdn2.microsoft.com/en-us/library/ms378428(SQL.90).aspx


Jimmy Wu, SQL Server
Disclaimer: This posting is provided “AS IS” with no warranties, and confers no rights

Comments (33)

  1. Deepak says:

    Hi..

    Please tell me how to download and install SQL Server 2005 JDBC driver

  2. dpblogs says:

    Hi Deepak,

    Please refer to http://msdn.microsoft.com/data/jdbc

    for download links of the SQL Server 2005 JDBC driver.  The installation information for both Windows and Unix platforms are in the download page.

    Jimmy

  3. Elina says:

    D:Elina>appletviewer Demo22.html

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

           at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:167)

           at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

           at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:118)

           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:164)

           at Demo22.paint(Demo22.java:38)

           at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)

           at sun.awt.RepaintArea.paint(RepaintArea.java:224)

           at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)

           at java.awt.Component.dispatchEventImpl(Component.java:4031)

           at java.awt.Container.dispatchEventImpl(Container.java:2024)

           at java.awt.Component.dispatchEvent(Component.java:3803)

           at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)

           at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh

    read.java:234)

           at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre

    ad.java:163)

           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

           at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

    Caused by: java.io.FileNotFoundException: D:Elinacommicrosoftjdbcsqlserver

    SQLServerDriver.class (The system cannot find the path specified)

           at java.io.FileInputStream.open(Native Method)

           at java.io.FileInputStream.<init>(FileInputStream.java:106)

           at java.io.FileInputStream.<init>(FileInputStream.java:66)

           at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection

    .java:70)

           at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLCon

    nection.java:161)

           at sun.applet.AppletClassLoader.getBytes(AppletClassLoader.java:279)

           at sun.applet.AppletClassLoader.access$100(AppletClassLoader.java:43)

           at sun.applet.AppletClassLoader$1.run(AppletClassLoader.java:157)

           at java.security.AccessController.doPrivileged(Native Method)

           at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:154)

           … 19 more

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

           at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:167)

           at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

           at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:118)

           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:164)

           at Demo22.paint(Demo22.java:38)

           at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)

           at sun.awt.RepaintArea.paint(RepaintArea.java:224)

           at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)

           at java.awt.Component.dispatchEventImpl(Component.java:4031)

           at java.awt.Container.dispatchEventImpl(Container.java:2024)

           at java.awt.Component.dispatchEvent(Component.java:3803)

           at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)

           at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh

    read.java:234)

           at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre

    ad.java:163)

           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

           at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

    Caused by: java.io.FileNotFoundException: D:Elinacommicrosoftjdbcsqlserver

    SQLServerDriver.class (The system cannot find the path specified)

           at java.io.FileInputStream.open(Native Method)

           at java.io.FileInputStream.<init>(FileInputStream.java:106)

           at java.io.FileInputStream.<init>(FileInputStream.java:66)

           at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection

    .java:70)

           at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLCon

    nection.java:161)

           at sun.applet.AppletClassLoader.getBytes(AppletClassLoader.java:279)

           at sun.applet.AppletClassLoader.access$100(AppletClassLoader.java:43)

           at sun.applet.AppletClassLoader$1.run(AppletClassLoader.java:157)

           at java.security.AccessController.doPrivileged(Native Method)

           at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:154)

           … 19 more

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

           at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:167)

           at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

           at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:118)

           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:164)

           at Demo22.paint(Demo22.java:38)

           at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)

           at sun.awt.RepaintArea.paint(RepaintArea.java:224)

           at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)

           at java.awt.Component.dispatchEventImpl(Component.java:4031)

           at java.awt.Container.dispatchEventImpl(Container.java:2024)

           at java.awt.Component.dispatchEvent(Component.java:3803)

           at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)

           at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh

    read.java:234)

           at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre

    ad.java:163)

           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

           at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

    Caused by: java.io.FileNotFoundException: D:Elinacommicrosoftjdbcsqlserver

    SQLServerDriver.class (The system cannot find the path specified)

           at java.io.FileInputStream.open(Native Method)

           at java.io.FileInputStream.<init>(FileInputStream.java:106)

           at java.io.FileInputStream.<init>(FileInputStream.java:66)

           at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection

    .java:70)

           at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLCon

    nection.java:161)

           at sun.applet.AppletClassLoader.getBytes(AppletClassLoader.java:279)

           at sun.applet.AppletClassLoader.access$100(AppletClassLoader.java:43)

           at sun.applet.AppletClassLoader$1.run(AppletClassLoader.java:157)

           at java.security.AccessController.doPrivileged(Native Method)

           at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:154)

           … 19 more

    plz help

  4. Elina says:

    i have set all class apth all things are right , i am using sql server 2000 and windows 2003 allready i downloaded JBDC Driver for sql server 2000 but why i am getting this error plz help me

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

           at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:167)

           at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

           at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:118)

           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:164)

           at Demo22.paint(Demo22.java:38)

           at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)

           at sun.awt.RepaintArea.paint(RepaintArea.java:224)

           at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)

           at java.awt.Component.dispatchEventImpl(Component.java:4031)

           at java.awt.Container.dispatchEventImpl(Container.java:2024)

           at java.awt.Component.dispatchEvent(Component.java:3803)

           at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)

           at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh

    read.java:234)

           at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre

    ad.java:163)

           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

           at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

    Caused by: java.io.FileNotFoundException: D:Elinacommicrosoftjdbcsqlserver

    SQLServerDriver.class (The system cannot find the path specified)

           at java.io.FileInputStream.open(Native Method)

           at java.io.FileInputStream.<init>(FileInputStream.java:106)

           at java.io.FileInputStream.<init>(FileInputStream.java:66)

           at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection

    .java:70)

           at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLCon

    nection.java:161)

           at sun.applet.AppletClassLoader.getBytes(AppletClassLoader.java:279)

           at sun.applet.AppletClassLoader.access$100(AppletClassLoader.java:43)

           at sun.applet.AppletClassLoader$1.run(AppletClassLoader.java:157)

           at java.security.AccessController.doPrivileged(Native Method)

           at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:154)

           … 19 more

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

           at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:167)

           at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

           at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:118)

           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:164)

           at Demo22.paint(Demo22.java:38)

           at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)

           at sun.awt.RepaintArea.paint(RepaintArea.java:224)

           at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)

           at java.awt.Component.dispatchEventImpl(Component.java:4031)

           at java.awt.Container.dispatchEventImpl(Container.java:2024)

           at java.awt.Component.dispatchEvent(Component.java:3803)

           at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)

           at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh

    read.java:234)

           at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre

    ad.java:163)

           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

           at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

    Caused by: java.io.FileNotFoundException: D:Elinacommicrosoftjdbcsqlserver

    SQLServerDriver.class (The system cannot find the path specified)

           at java.io.FileInputStream.open(Native Method)

           at java.io.FileInputStream.<init>(FileInputStream.java:106)

           at java.io.FileInputStream.<init>(FileInputStream.java:66)

           at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection

    .java:70)

           at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLCon

    nection.java:161)

           at sun.applet.AppletClassLoader.getBytes(AppletClassLoader.java:279)

           at sun.applet.AppletClassLoader.access$100(AppletClassLoader.java:43)

           at sun.applet.AppletClassLoader$1.run(AppletClassLoader.java:157)

           at java.security.AccessController.doPrivileged(Native Method)

           at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:154)

           … 19 more

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

           at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:167)

           at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

           at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:118)

           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:164)

           at Demo22.paint(Demo22.java:38)

           at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)

           at sun.awt.RepaintArea.paint(RepaintArea.java:224)

           at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)

           at java.awt.Component.dispatchEventImpl(Component.java:4031)

           at java.awt.Container.dispatchEventImpl(Container.java:2024)

           at java.awt.Component.dispatchEvent(Component.java:3803)

           at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)

           at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh

    read.java:234)

           at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre

    ad.java:163)

           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

           at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

    Caused by: java.io.FileNotFoundException: D:Elinacommicrosoftjdbcsqlserver

    SQLServerDriver.class (The system cannot find the path specified)

           at java.io.FileInputStream.open(Native Method)

           at java.io.FileInputStream.<init>(FileInputStream.java:106)

           at java.io.FileInputStream.<init>(FileInputStream.java:66)

           at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection

    .java:70)

           at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLCon

    nection.java:161)

           at sun.applet.AppletClassLoader.getBytes(AppletClassLoader.java:279)

           at sun.applet.AppletClassLoader.access$100(AppletClassLoader.java:43)

           at sun.applet.AppletClassLoader$1.run(AppletClassLoader.java:157)

           at java.security.AccessController.doPrivileged(Native Method)

           at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:154)

           … 19 more

  5. dpblogs says:

    Hi Elina,

    This type of questions that require back and forth troubleshooting are probably best suited for the newsgroup or forum.  The JDBC newsgroup can be found at http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.sqlserver.jdbcdriver and the JDBC forum can be found at http://forums.microsoft.com/msdn/showforum.aspx?forumid=87&siteid=1

    Looking at the call stack I noticed there is a file not found exception

    "Caused by: java.io.FileNotFoundException: D:ElinacommicrosoftjdbcsqlserverSQLServerDriver.class (The system cannot find the path specified)"

    You mentioned that you have all the classpath set correctly.  If you can post this question on either the newsgroup or forum with additional app configuration, the Java environment settings, and the class name you are using, there will be a broader set of people in the community to help answer your question.

    Jimmy

  6. Rajesh says:

    Hello friends,

    I had tried to connect the SQL Server 2000 Data Base using the JDBC.

    My Programming code is

    import java.*;

    public class Connect{

        private java.sql.Connection  con = null;

        private final String url = "jdbc:microsoft:sqlserver://";

        private final String serverName= "localhost";

        private final String portNumber = "1433";

        private final String databaseName= "pubs";

        private final String userName = "user";

        private final String password = "password";

        // Informs the driver to use server a side-cursor,

        // which permits more than one active statement

        // on a connection.

        private final String selectMethod = "cursor";

        // Constructor

        public Connect(){}

        private String getConnectionUrl(){

             return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";

        }

        private java.sql.Connection getConnection(){

             try{

                  Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

                  con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);

                  if(con!=null) System.out.println("Connection Successful!");

             }catch(Exception e){

                  e.printStackTrace();

                  System.out.println("Error Trace in getConnection() : " + e.getMessage());

            }

             return con;

         }

        /*

             Display the driver properties, database details

        */

        public void displayDbProperties(){

             java.sql.DatabaseMetaData dm = null;

             java.sql.ResultSet rs = null;

             try{

                  con= this.getConnection();

                  if(con!=null){

                       dm = con.getMetaData();

                       System.out.println("Driver Information");

                       System.out.println("tDriver Name: "+ dm.getDriverName());

                       System.out.println("tDriver Version: "+ dm.getDriverVersion ());

                       System.out.println("nDatabase Information ");

                       System.out.println("tDatabase Name: "+ dm.getDatabaseProductName());

                       System.out.println("tDatabase Version: "+ dm.getDatabaseProductVersion());

                       System.out.println("Avalilable Catalogs ");

                       rs = dm.getCatalogs();

                       while(rs.next()){

                            System.out.println("tcatalog: "+ rs.getString(1));

                       }

                       rs.close();

                       rs = null;

                       closeConnection();

                  }else System.out.println("Error: No active Connection");

             }catch(Exception e){

                  e.printStackTrace();

             }

             dm=null;

        }    

        private void closeConnection(){

             try{

                  if(con!=null)

                       con.close();

                  con=null;

             }catch(Exception e){

                  e.printStackTrace();

             }

        }

        public static void main(String[] args) throws Exception

          {

             Connect myDbTest = new Connect();

             myDbTest.displayDbProperties();

          }

    }

    When I was run this program it is displaying as

    java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.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 Connect.getConnection(Connect.java:24)

    at Connect.displayDbProperties(Connect.java:42)

    at Connect.main(Connect.java:78)

    Error Trace in getConnection() : com.microsoft.jdbc.sqlserver.SQLServerDriver

    Error: No active Connection

    Plese help me any one knows where i did a mistake.

    My Email-Id is rajeshlab@yahoo.com

  7. Mugunthan says:

    Are you trying to use the SQL2005 driver then your url is wrong the right URL is

    com.microsoft.sqlserver.jdbc.SQLServerDriver

  8. Amarnath Reddy says:

    Hi,

    I have tried to use the SQL Server JDBC Driver for SQL 2005. I keep getting "java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver" . I have added "sqljdbc.jar" to mu PATH variable but still the error persists

  9. dpblogs says:

    Hi Amarnath,

    Can you confirm that you are specifying the full path to the sqljdbc.jar file in the JAVA classpath when starting the application?  Or, are you specifying the directory where sqljdbc.jar exists in the system environment PATH?

    example:

     java -cp .;c:MSJDBCsqljdbc_1.2enusqljdbc.jar …

    HTH,

    Jimmy Wu

  10. rahul says:

    i can’t create connection using SQL server 2005 using java.

  11. shivaraja says:

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

    I am getting this exception,please help me to resolve this,added sqljdbc4.jar in the class path.

  12. Mugunthan Mugundan [MSFT] says:

    What is your Java version. How are you invoking your app.

  13. kumon says:

    How to connect sql server 2008, always throw this exception! Thanks very much!

  14. dpblogs says:

    kumon,

    Please provide a more specific error message and more information regarding your scenario back here in the blog or to this forum:

    http://social.msdn.microsoft.com/forums/en-US/sqldataaccess/threads/

    –Tres London [SQL Server]

  15. Trying2BGeek says:

    I am using eclipse and I have added both sqljdbc4.jar and sqljdbc.jar in classpath. Still I am getting

    ClassNotFoundException:

    com.microsoft.jdbc.sqlserver.SQLServerDriver

    SQLException:No suitable driver found for jdbc:sqlserver://localhost:1433;databaseName=analyticsdbuser=sa;password=XXXXX

  16. Mugunthan Mugundan- MSFT says:

    Eclipse sometime uses its  own JVM. I would try adding the appropriate jar (e.g. jdbc4.jar if you are using 1.6 VM) in the libaries of the eclipse project you are working on. The eclipse reference should show you how to add a library for your proejct.

  17. Kareen says:

    manage to get the codes to work in eclipse! 🙂

    2 parts of the codes needs changes…the following needs to be changed from:

    1:

    private final String url = "jdbc:microsoft:sqlserver://";

    to

       private final String url = "jdbc:sqlserver://";

    AND

    2:

    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

    to

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

    good luck! 🙂

  18. Yogish says:

    While connecting to remote database i’m getting this exception..

  19. webcom says:

    getting the same error.

    String

    driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";

    Class.forName(driver); //Class Not Found Exception is here

    adding reference to .jar to veryfy the className

    import com.microsoft.sqlserver.jdbc.SQLServerDriver;

    the classpath is registered via cmd as:

    >java -cp .;d:ZipEclipse_ZIPMicrosoftSQLServerJDBCDriver3.0sqljdbc_3.0enusqljdbc4.jar; //using jre6

    the same jar path added to classpath in Windows env. variables;

    Finally tried to create instance as:

    import com.microsoft.sqlserver.jdbc.SQLServerDriver;

    SQLServerDriver driv=new SQLServerDriver();//Class Not Found Exception

    Followed all recommendations from the Help provided in Microsoft SQLServer JDBCDriver3.0 installation package. Nothing is working!

    Microsoft! why ??

  20. ANkitSharma says:

    My program is ………

    import java.sql.*;

    import java.applet.*;

    import java.awt.Graphics;

    /*<applet code=check1.class width=400 height=600>

    </applet>

    */

    public class check1 extends Applet

    {

       public void paint(Graphics g)

       {

            String s = connectsql();

            g.drawString(s, 5, 15);

       }

       public String connectsql()

       {

            String sat_id= "sat_id";

            String sat_name= "sat_name";

            String ret = "";

            try

            {

                //Driver d = (Driver)Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();

                String url = "jdbc:sqlserver://localhost:1433;databaseName=master;selectMethod=cursor;";

                java.sql.Connection con = null;

                try

                {

                    con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433");

                    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

                    con = java.sql.DriverManager.getConnection(url, sat_id, sat_name);

                    if (con != null)

                    {

                        ret = "connected";

                        con.close();

                        con = null;

                    }

                    else

                    {

                        ret = "failed to connect";

                    }

                 }

                catch(ClassNotFoundException cnfe)

                {

                        ret = cnfe.toString();

                }

            }

           catch (Exception e)

            {

                ret = "caught new driver exception: " + e.toString();

            }

           return ret;

        }

    Each time I Run it with Appletviewer It shows Following Exception::::

    java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.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 Connect.getConnection(Connect.java:24)

    at Connect.displayDbProperties(Connect.java:42)

    at Connect.main(Connect.java:78)

    Error Trace in getConnection() : com.microsoft.jdbc.sqlserver.SQLServerDriver

    Error: No active Connection

    and how can I check my jdbc sql server 2005 ….and its path…

  21. ANkitSharma says:

    My program is ………

    import java.sql.*;

    import java.applet.*;

    import java.awt.Graphics;

    /*<applet code=check1.class width=400 height=600>

    </applet>

    */

    public class check1 extends Applet

    {

       public void paint(Graphics g)

       {

            String s = connectsql();

            g.drawString(s, 5, 15);

       }

       public String connectsql()

       {

            String sat_id= "sat_id";

            String sat_name= "sat_name";

            String ret = "";

            try

            {

                //Driver d = (Driver)Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();

                String url = "jdbc:sqlserver://localhost:1433;databaseName=master;selectMethod=cursor;";

                java.sql.Connection con = null;

                try

                {

                    con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433");

                    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

                    con = java.sql.DriverManager.getConnection(url, sat_id, sat_name);

                    if (con != null)

                    {

                        ret = "connected";

                        con.close();

                        con = null;

                    }

                    else

                    {

                        ret = "failed to connect";

                    }

                 }

                catch(ClassNotFoundException cnfe)

                {

                        ret = cnfe.toString();

                }

            }

           catch (Exception e)

            {

                ret = "caught new driver exception: " + e.toString();

            }

           return ret;

        }

    Each time I Run it with Appletviewer It shows Following Exception::::

    java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.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 Connect.getConnection(Connect.java:24)

    at Connect.displayDbProperties(Connect.java:42)

    at Connect.main(Connect.java:78)

    Error Trace in getConnection() : com.microsoft.jdbc.sqlserver.SQLServerDriver

    Error: No active Connection

    and how can I check my jdbc sql server 2005 ….and its path…

  22. gaurav says:

    i successfully execute the sql 2005 connectivity program. If anyone have worry then contect me.

    I'll give you complete running code in java .

    E.MAIL.     chaudharygaurav567@gmail.com

  23. santhosh says:

    place the sqljdbc4.jar file into u r web-inf –>lib;

  24. aks says:

    If you are using an IDE like jDeveloper or eclipse, make sure you add the classpaths to the project

    properties/preferences options.

  25. Ian Visser says:

    It would appear, that although Microsoft claims that both the 2.0 and 3.0 drivers work with JRE 1.5.  If I do I get a ClassNotFoundException or java.lang.UnsupportedClassVersionError: Bad version number in .class file

    Running under JRE 1.6 solves this problem.  

    Would Microsoft consider rebuilding de drivers with 1.5 compiler?  Clearly this was the intention.

  26. Kate says:

    santhosh  is right place the sqljdbc.jar or sqljdbc4.jar file into your web-inf –>lib;

    it worked for me

  27. Kate says:

    santhosh  is right place the sqljdbc.jar or sqljdbc4.jar file into your web-inf –>lib;

    it worked for me

  28. PhilipG says:

    Still getting Class not found exception.

    I'm using Eclipse.

    I've installed ms jdbc version 3 for connecting to sql server 2008 R2.

    The system variable CLASSPATH is set to the full path of sqljdbc4.jar because I'm using jre 1.6.

    I've address sqljdbc4.jar to Eclipse libraries for my project.

    If you've managed to connect to sql server through eclipse or have any other suggestion beside what I've tried, I'd appreciate your help.

    Here's what I've done so far.

    Step 1.

    Exception is thrown at:

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

    Step 2.

    I replaced the above line with:

    Class.forName("com.microsoft.sqlserver.jdbc.SQLDataSource");

    but I got the same exception.

    Step 3.

    I:

    import com.microsoft.sqlserver.jdbc.*;

    and replaced the call to Class.forName with:

    SQLServerDataSource ds = new SQLServerDataSource();

    ds.setUser("myAppUser");

    ds.setPassword("myAppPwd");

    ds.setServerName("remoteServer");

    ds.setPortNumber(1433);

    ds.setDatabaseName("myDB");

    Exception at line:

    SQLServerDataSource ds = new SQLServerDataSource();

    Step 4.

    I copied sqljdbc4.jar to my project's WEB-INFlib and repeated step 1 to 4.

    Result = Class not found exception.

    Step 5:

    While sqljdbc4.jar in web-inflib, I removed sqljdbc4.jar from eclipse libraries and repeated step 1 to 4.

    Result = Class not found exception.

    Step 6:

    Add sqljdbc4.jar in the web-inflib to eclipse libraries and repeated step 1 to 4.

    Result = Class not found exception.

    Any other suggestions?

  29. Harry says:

    Please let us know if someone has got this worked. I'm on the same boat as of PhilipG.

    curious to know, what did I miss. Please help.

  30. Daniel says:

    Eclipse Package Explorer -> right click over project folder -> Properties -> Java Build Path -> Libraries -> Add External JARs…

    works for me

  31. allan says:

    Why on earth would you change this?  Some of us have deadlines to hit and when this issue occurs in a 3rd party library it has very real impact.

  32. punitha says:

    sir im using eclipse indigo IDE, while i try to connect with the database, it throws an exception like "java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver". i already added sqljdbc4-2.0 jar in the external libraries.but im getting trouble. Any one please help me

  33. Anastasya says:

    Hello everybody,

    I resolved this issue this way:

    I'm trying to connect to SQL Server 2008 R2.

    I'm using Eclipse and JDK 1.7.0_65.

    CLASSPATH definition – C:Program Files (x86)Microsoft JDBC Driver 4.0 for SQL Serversqljdbc_4.0enusqljdbc4.jar

    Driver – Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

    Connection string – jdbc:sqlserver://your_iserver_ip:1433;DatabaseName=Test

    After defining all mentioned above you need to copy sqljdbc4.jar file to your project folder and then to import the jar file into eclipse.

    Instructions for jar import into Eclipse:

    Right click on your project > Properties > Java build path > Add external JARs button >  choose relevant jar file.

    Good luck!