Search code examples
javasql-serverwebsphere-libertymssql-jdbcopen-liberty

Connect to Sql Server on liberty using mssql-jdbc


I'm trying to connect to a Sql Server database from a liberty server. Doesn't work as I'm getting a 500 from the liberty server and the logs give me this error message: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: SQL Server did not return a response.

My xml:

<library id="sqlServerLib2" apiTypeVisibility="spec,ibm-api,api,third-party"
    <fileset dir="${server.config.dir}/lib/global" includes="mssql-jdbc-6.1.0.jre8.jar"/>
</library>

<dataSource id="myDataSource" jndiName="jdbc/myDataSource">
    <jdbcDriver libraryRef="sqlServerLib2"/>
    <properties.microsoft.sqlserver
                        serverName="localhost"
                        portNumber="8080"
                        databaseName="my_db"
                        user="user"
                        password="password"/>
    <connectionManager maxPoolSize="100" minPoolSize="0"/>
</dataSource>

I've looked at IBM's pages. Didn't give much help.

I've also googled the error message but people usually say that I should just update my driver to at least 4.2. I'm using 6.1, so that doesn't really apply.

What am I missing here? Thanks.

EDIT: I took a look at Microsoft's pages and found that i was using an incompatible jdbc-api version. I changed this from 4.0 to 4.1.

<featureManager>
    <feature>jdbc-4.1</feature>
</featureManager>

I also defined the dataSource and connection pool classes in my datasource.

<jdbcDriver libraryRef="sqlserverLib2" 
javax.sql.DataSource="com.microsoft.sqlserver.jdbc.SQLServerDataSource"
javax.sql.ConnectionPoolDataSource="com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource"/>

Now I'm getting a java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDataSource.

I tried using the mssql-jdbc-6.1.0.jre7.jar(java 7) instead. Then all of a sudden i worked. What am I doing wrong with the jre8 version of the driver?


Solution

  • The main error was that I used a version of the jdbc-api that was incompatible with the mssql-jdbc-6.1.0.jre8.jar driver. Changing to version 4.1 fixed it.

    The classNotFoundException was just a blunder on my part(forgot to update the pom.xml)