locked
What is a suitable JDBC driver for connecting to SQL Azure or SQL Server 2008 R2? RRS feed

  • Question

  • The latest one sqljdbc4.jar does not seem to work.

     

    For example you get the following exception:

    java.sql.SQLException: No suitable driver found for jdbc:sqlserver://192.168.1.102:1433;databaseName=AdventureWorks;integrate
    dSecurity=true;


    mysorian
    Monday, August 2, 2010 3:49 PM

Answers

  • No..but I dont think it would be a problem ...because..I'm using Windows Vista...and tested it with Windows Server 2008 no problem with that.
    Thursday, August 5, 2010 12:38 PM

All replies

  • Platform : windows 7 Ultimate
    JVM :Java Version 1.6.0_21 from SUN Microsystems Inc.
    "jdbc:sqlserver://192.168.1.102:1433;"+"databaseName=AdventureWorks;user=UserName;password=*****";

    Computer, SQL Server in the same domain


    SQL Server 2008 R2 is local
    Server is on
    Server instance is a named instance
    Computer user account (SQL Server 2008 Admin account)

    No transactions

    Just testing Microsoft sample code:
    connectURL from the JDBC download

    Because the long file names were problematic the *.jar files were placed in a different location(folder JTDS) and the classpath was inline

    JDBC 3.0 has two sets of sqljdbc.jar and sqljdbc4.jar. Using any of these the exception is same


    C:\Users\jay>java -classpath C:\JTDS\sqljdbc.jar connectURL
    Exception in thread "main" java.lang.NoClassDefFoundError: connectURL
    Caused by: java.lang.ClassNotFoundException: connectURL
            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)
    Could not find the main class: connectURL.  Program will exit.

    C:\Users\jay>java -classpath C:\JTDS\sqljdbc4.jar connectURL
    Exception in thread "main" java.lang.NoClassDefFoundError: connectURL
    Caused by: java.lang.ClassNotFoundException: connectURL
            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)
    Could not find the main class: connectURL.  Program will exit.

    C:\Users\jay>java -classpath C:\JTDS\sqljdbc4.jar connectURL
    Exception in thread "main" java.lang.NoClassDefFoundError: connectURL
    Caused by: java.lang.ClassNotFoundException: connectURL
            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)
    Could not find the main class: connectURL.  Program will exit.

    C:\Users\jay>java -classpath C:\JTDS\sqljdbc.jar connectURL
    Exception in thread "main" java.lang.NoClassDefFoundError: connectURL
    Caused by: java.lang.ClassNotFoundException: connectURL
            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)
    Could not find the main class: connectURL.  Program will exit.

    C:\Users\jay>


    mysorian
    • Merged by KJian_ Thursday, August 5, 2010 3:28 AM
    Monday, August 2, 2010 5:11 PM
  • Hi,

    I am not familiar with Java and JDBC, but I think you can refer to the following links to connect to SQL Azure using JDBC:

    http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/498ed49e-08c3-427b-acc3-048bfa3898d6

    http://consultingblogs.emc.com/nileeshabojjawar/archive/2010/03/25/azure-sql-with-spring-hibernate.aspx

    http://blogs.msdn.com/b/jcurrier/archive/2009/03/29/sds-java-jdbc-examples.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, August 3, 2010 3:01 AM
  • Hi,

    Jayaram,

    I have used the same sqljdbc4.jar in my application to connect it with SQL Azure It is working fine.The version of JRE is 1.6 ..can u please check the version of your JRE?

     

    Thanks & Regards,

    Writs

    Wednesday, August 4, 2010 5:10 AM
  • The settings in my case are posted to the following thread as well.

    http://social.msdn.microsoft.com/Forums/en-US/sqldataaccess/thread/71798434-ae11-4e2d-9853-7a2a9c9d2135

     

    Can you take a look at it?

    Thanks

     

     


    mysorian
    Wednesday, August 4, 2010 4:08 PM
  • Hi Writs,

    I merged the two threads into one.  Please see the first reply in this thread.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, August 5, 2010 4:36 AM
  • Hi,

    Jayaram,

    I have gone through your setting...and looked on my settings...I have used JDBC 2.0 and used only sqljdbc4.0.jar...not the sqljdbc.jar.Please change it accordingly..I think you first take out the sqljdbc.jar from your application (leave the sqljdbc4.0.jar untouched) and try.Please let me know...

    Thanks & Regards,

    Ritun

    Thursday, August 5, 2010 5:27 AM
  • Jayaram

    From the error I found that in Main is not getting the class properly can you please add these jars in your class path?

    Thanks & Regards,

    Ritun

    Thursday, August 5, 2010 5:33 AM
  • Like this

    set CLASSPATH=%JAVA_HOME%\lib\sqljdbc4.jar;

    Thanks & Regards,

    Writs

    Thursday, August 5, 2010 5:38 AM
  • Is your platform Windows 7?

     

     


    mysorian
    Thursday, August 5, 2010 12:15 PM
  • No..but I dont think it would be a problem ...because..I'm using Windows Vista...and tested it with Windows Server 2008 no problem with that.
    Thursday, August 5, 2010 12:38 PM
  • The classpath had a syntax error and the connection string had a wrong attribute.

    sqljdbc4.jar with jre 1.6 is a good mix for SQL Server 2008


    mysorian
    Thursday, August 5, 2010 1:25 PM
  • Use this JDBC 3.0 version: Microsoft JDBC Driver 3.0 for SQL Server and SQL Azure   


    Selcin Turkarslan
    Tuesday, April 19, 2011 7:04 PM