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

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

  • Comments 33

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

Leave a Comment
  • Please add 2 and 8 and type the answer here:
  • Post
  • 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.

  • 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! :)

  • While connecting to remote database i'm getting this exception..

  • 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:\Zip\Eclipse_ZIP\MicrosoftSQLServerJDBCDriver3.0\sqljdbc_3.0\enu\sqljdbc4.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 ??

  • 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...

  • 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...

  • 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

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

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

    properties/preferences options.

  • 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.

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

    it worked for me

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

    it worked for me

  • 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-INF\lib and repeated step 1 to 4.

    Result = Class not found exception.

    Step 5:

    While sqljdbc4.jar in web-inf\lib, 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-inf\lib to eclipse libraries and repeated step 1 to 4.

    Result = Class not found exception.

    Any other suggestions?

  • 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.

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

    works for me

Page 2 of 3 (33 items) 123