Hobione's Weblog

Living & Breathing in Web 2.0 Era

SSL connection from Java to MSSQL Database Server using JDBC driver

First of all, need to get the self-signed certificate from database administrator and install/import to the following path.
C:\Program Files\Java\jdk1.7.0_17\jre\lib\security\cacerts

How to install ssl certificate?
Step 1: Get the certificate from certificate owner, it is usually .cer file (SQLcert.cer)
Step 2: Make a dir under c drive (c:\certificate)
Step 3: Copy the cacerts from C:\Program Files\Java\jdk1.7.0_17\jre\lib\security\cacerts to c:\certificate
Step4: Copy SQLcert.cer to c:\certificate
Step5: Open up a command prompt and change directory to c:\certificate
Step6: Execute this command
keytool -import -keystore cacerts -file SQLcert.cer

How to import SSL certificate

Step8: Copy cacerts file back to the original path –> *C:\Program Files\Java\jdk1.7.0_17\jre\lib\security

How to install jdbc4 driver to local maven repository?

Missing artifact com.microsoft.sqlserver:sqljdbc4:jar:4.0
To add the jar file in pom.xml since Microsoft don’t make this available via any maven repository.

Download the jar from the Microsoft website, and then manually install it into local maven repository using following command.
mvn install:install-file -Dfile=sqljdbc4.jar –DgroupId=com.microsoft.sqlserver –DartifactId=sqljdbc4 -Dversion=4.0 -Dpackaging=jar

How to install jdbc4 driver to local maven repository

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>

How to setup jdbc ssl connection string for MSSQL server 2012?
jdbc:sqlserver://arc-xxx-xxx.xxx.xxx.com\\CSDTEST;databaseName=surveySys;EncryptionMethod=ssl

Pay attentions on slashes (forward slash vs backward slash: before server name, it has forward slash but after the server name there are two back slashes). I also had to use full server name instead of an ip address.

I was able to connect to the SQL server after few days of hard work.

 

How to list all certificates in cacerts file?
c:\Program Files\Java\jdk1.7.0_17\jre\lib\security>keytool -list -v -keystore cacerts

August 18, 2014 Posted by | SSL | , | Leave a comment