JDBC to SQL Azure


Using the open source jTDS JDBC Driver, you can connect to SQL Azure.

 

Driver class name: net.sourceforge.jtds.jdbc.Driver

Database URL: jdbc:jtds:sqlserver://<server>.database.windows.net:1433/<databasename>;ssl=require

Username: (in the form username@server from SQL Azure)

 

The key thing is the “ssl=require” placed at the end of the connection string. SQL Azure SSL encrypts the data on the wire, and requires SSL. Which is rather a good thing.

Hope this saves someone some time.


Comments (11)

  1. Thank you for those information, it helps me to start working with Azure from our open source bpm java product.

    Regards

    Olivier

  2. JackBean says:

    So, is jTDS an officially supported JDBC Driver?

  3. Dave says:

    Thank you very much for this. It saved me lots of time. Much appreciated.

  4. ganapathi says:

    i am using jtds 1.2 .jar for SQL Azure getting error like this any solution

    java.lang.Exception: Connection failed with unspecified error.

    at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:109)

    at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:53)

    at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.open(JDBCConnection.java:72)

    at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnectionFactory.createConnection(JDBCConnectionFactory.java:53)

    at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)

    at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:355)

    at org.eclipse.datatools.connectivity.ui.PingJob.createTestConnection(PingJob.java:76)

    at org.eclipse.datatools.connectivity.ui.PingJob.run(PingJob.java:59)

    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

  5. @ganapathi : has the IP address you are attempting to connect from been added to the Permitted IP addresses in the Firewall rules (SQL Azure)

  6. I used following code to use jtds 1.2.7:

    Class.forName("net.sourceforge.jtds.jdbc.Driver");

    connection = DriverManager.getConnection("jdbc:jtds:sqlserver://xxx.database.windows.net:1433/database;ssl=required", "account", "pwd");

    and got follow error log:

    06-03 09:13:52.030: I/System.out(4667): waiting for debugger to settle…

    06-03 09:13:52.230: I/System.out(4667): waiting for debugger to settle…

    06-03 09:13:52.430: I/System.out(4667): debugger has settled (1434)

    06-03 09:13:52.590: E/(4667): file /data/data/com.nvidia.NvCPLSvc/files/driverlist.txt: not found!

    06-03 09:13:52.590: I/(4667): Attempting to load EGL implementation /system/lib//egl/libEGL_tegra_impl

    06-03 09:13:52.595: I/(4667): Loaded EGL implementation /system/lib//egl/libEGL_tegra_impl

    06-03 09:13:52.630: I/(4667): Loading GLESv2 implementation /system/lib//egl/libGLESv2_tegra_impl

    06-03 09:13:55.685: W/AzureTest(4667): Thread start

    06-03 09:13:56.700: W/dalvikvm(4667): VFY: unable to resolve static method 3409: Lcom/sun/net/ssl/SSLContext;.getInstance (Ljava/lang/String;)Lcom/sun/net/ssl/SSLContext;

    06-03 09:13:56.700: W/dalvikvm(4667): Link of class 'Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$1;' failed

    06-03 09:13:56.700: E/dalvikvm(4667): Could not find class 'net.sourceforge.jtds.ssl.SocketFactoriesSUN$1', referenced from method net.sourceforge.jtds.ssl.SocketFactoriesSUN$TdsTlsSocketFactory.trustManagers

    06-03 09:13:56.705: W/dalvikvm(4667): VFY: unable to resolve new-instance 744 (Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$1;) in Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$TdsTlsSocketFactory;

    06-03 09:13:56.705: W/dalvikvm(4667): Link of class 'Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$1;' failed

  7. I used following code:

    Class.forName("net.sourceforge.jtds.jdbc.Driver");

    connection = DriverManager.getConnection("jdbc:jtds:sqlserver://xxx.database.windows.net:1433/database;ssl=required", "account", "pwd");

    and got following error log:

    06-03 09:13:52.030: I/System.out(4667): waiting for debugger to settle…

    06-03 09:13:52.230: I/System.out(4667): waiting for debugger to settle…

    06-03 09:13:52.430: I/System.out(4667): debugger has settled (1434)

    06-03 09:13:52.590: E/(4667): file /data/data/com.nvidia.NvCPLSvc/files/driverlist.txt: not found!

    06-03 09:13:52.590: I/(4667): Attempting to load EGL implementation /system/lib//egl/libEGL_tegra_impl

    06-03 09:13:52.595: I/(4667): Loaded EGL implementation /system/lib//egl/libEGL_tegra_impl

    06-03 09:13:52.630: I/(4667): Loading GLESv2 implementation /system/lib//egl/libGLESv2_tegra_impl

    06-03 09:13:55.685: W/AzureTest(4667): Thread start

    06-03 09:13:56.700: W/dalvikvm(4667): VFY: unable to resolve static method 3409: Lcom/sun/net/ssl/SSLContext;.getInstance (Ljava/lang/String;)Lcom/sun/net/ssl/SSLContext;

    06-03 09:13:56.700: W/dalvikvm(4667): Link of class 'Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$1;' failed

    06-03 09:13:56.700: E/dalvikvm(4667): Could not find class 'net.sourceforge.jtds.ssl.SocketFactoriesSUN$1', referenced from method net.sourceforge.jtds.ssl.SocketFactoriesSUN$TdsTlsSocketFactory.trustManagers

    06-03 09:13:56.705: W/dalvikvm(4667): VFY: unable to resolve new-instance 744 (Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$1;) in Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$TdsTlsSocketFactory;

    06-03 09:13:56.705: W/dalvikvm(4667): Link of class 'Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$1;' failed

  8. I tried to use jtds 1.2.7 on Android 4.0 by following code:

    public class TestThread extends Thread {

    @Override

       public void run() {

          …

          Connection connection = null;

          try

          {

                Class.forName("net.sourceforge.jtds.jdbc.Driver");

                connection = DriverManager.getConnection("jdbc:jtds:sqlserver://xxx.database.windows.net:1433/database;ssl=required", "account", "pwd");

    and got following error log:

    06-04 09:17:02.143: W/AzureTest(32604): Thread start

    06-04 09:17:03.488: W/dalvikvm(32604): VFY: unable to resolve static method 3407: Lcom/sun/net/ssl/SSLContext;.getInstance (Ljava/lang/String;)Lcom/sun/net/ssl/SSLContext;

    06-04 09:17:03.488: W/dalvikvm(32604): Link of class 'Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$1;' failed

    06-04 09:17:03.488: E/dalvikvm(32604): Could not find class 'net.sourceforge.jtds.ssl.SocketFactoriesSUN$1', referenced from method net.sourceforge.jtds.ssl.SocketFactoriesSUN$TdsTlsSocketFactory.trustManagers

    06-04 09:17:03.488: W/dalvikvm(32604): VFY: unable to resolve new-instance 743 (Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$1;) in Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$TdsTlsSocketFactory;

    06-04 09:17:03.488: W/dalvikvm(32604): Link of class 'Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$1;' failed

    06-04 09:17:03.493: W/dalvikvm(32604): threadid=12: thread exiting with uncaught exception (group=0x41d8c2d0)

    06-04 09:17:03.498: E/AndroidRuntime(32604): FATAL EXCEPTION: Thread-2262

    06-04 09:17:03.498: E/AndroidRuntime(32604): java.lang.NoClassDefFoundError: com.sun.net.ssl.SSLContext

    06-04 09:17:03.498: E/AndroidRuntime(32604):  at net.sourceforge.jtds.ssl.SocketFactoriesSUN$TdsTlsSocketFactory.factory(SocketFactoriesSUN.java:174)

    06-04 09:17:03.498: E/AndroidRuntime(32604): at net.sourceforge.jtds.ssl.SocketFactoriesSUN$TdsTlsSocketFactory.getFactory(SocketFactoriesSUN.java:157)

    06-04 09:17:03.498: E/AndroidRuntime(32604): at net.sourceforge.jtds.ssl.SocketFactoriesSUN$TdsTlsSocketFactory.createSocket(SocketFactoriesSUN.java:86)

    06-04 09:17:03.498: E/AndroidRuntime(32604): at net.sourceforge.jtds.jdbc.SharedSocket.enableEncryption(SharedSocket.java:332)

    06-04 09:17:03.498: E/AndroidRuntime(32604): at net.sourceforge.jtds.jdbc.TdsCore.negotiateSSL(TdsCore.java:554)

    06-04 09:17:03.498: E/AndroidRuntime(32604): at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:350)

    06-04 09:17:03.498: E/AndroidRuntime(32604): at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:188)

    06-04 09:17:03.498: E/AndroidRuntime(32604): at java.sql.DriverManager.getConnection(DriverManager.java:175)

    06-04 09:17:03.498: E/AndroidRuntime(32604): at java.sql.DriverManager.getConnection(DriverManager.java:209)

    06-04 09:17:03.498: E/AndroidRuntime(32604): at com.benecheck.azuretest.TestThread.run(TestThread.java:38)

  9. As I am not deeply involved in this as I once was, I suggest popping over to msdn.microsoft.com/…/gg715284.aspx or http://www.windowsazure.com/…/java

  10. IGx89 says:

    -Djsse.enableCBCProtection=false is needed too — that did the trick for me. See stackoverflow.com/…/connecting-to-azure-sql-db-via-jtds-on-an-android-device