question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SQL Server JDBC Driver failure

See original GitHub issue

Driver version

7.0.0 jre8

SQL Server version

Microsoft SQL Server 2005 - 9.00.5000.00 (Intel X86) Dec 10 2010 10:56:29 Copyright © 1988-2005 Microsoft Corporation Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 2)

Client Operating System

Windows 7 Enterprise, Service Pack 1

JAVA/JVM version

1.8.0_121

Table schema

Unavailable

Problem description

  1. Expected behaviour:

For our Java application to make connections with the SQL Server database once our Java application is deployed to our development server. The driver does work locally when running our application locally.

  1. Actual behaviour:

The JDBC driver fails to establish a connection to our database when deployed to our development server.

  1. Error message/stack trace:

We get the following error when running our code within the stack trace when executing the Java code in our development server:

**org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [com.microsoft.sqlserver.jdbc.SQLServerDriver]**

java.lang.ClassNotFoundException: Could not load requested class : com.microsoft.sqlserver.jdbc.SQLServerDriver

We suspect the first two errors above for Hibernate are being caused by the failure of the JDBC driver.

Also we get the following error when trying to connect to the database via our IDE:

The driver could not establish a secure connection to SQL Server by using Secure Sockets layer (SSL) encryption. Error: “sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target”.

No idea if this error is also related to the errors above.

  1. Any other details that can be helpful:

JDBC trace logs

Unavailable

Reproduction code

We are using Hibernate instead of SQL queries within the Java code:

sectionUpdateEntity.setOnPressDate(GetOnPressDateForFSILogTable(insertDate, regionID, marketID, stufferInd)); sectionUpdateEntity.setPlacementSignOff(Timestamp.valueOf(now));

                //set the rest of the fields to null
                sectionUpdateEntity.setViewAndAssign(null);
                sectionUpdateEntity.setSpiderUpdate(null);
                sectionUpdateEntity.setSpineRowUpdate(null);
                sectionUpdateEntity.setUploadToES(null);

                // Return the OnPressDate to pass into ES later, needed only for Actions 1 through 4
                datesReturned.add(sectionUpdateEntity.getOnPressDate().toString());
                lists.add(datesReturned);

// Commit Changes entityManager.getTransaction().commit();

##Additional Info:

So far I have tried the following to resolve the issue:

  •    Updated to version 7.0 for jre8 of the driver from 4.2
    
  •    Added the following to the end of the connection string: "encrypt=true;trustServerCertificate=true";  
    

(As shown in: https://docs.microsoft.com/en-us/sql/connect/jdbc/connecting-with-ssl-encryption?view=sql-server-2017)

  •    Checked the java.security file to make sure that the following was in that file: security.provider.1=sun.security.provider.Sun
    

(As shown in: https://blogs.msdn.microsoft.com/jdbcteam/2008/09/09/the-driver-could-not-establish-a-secure-connection-to-sql-server-by-using-secure-sockets-layer-ssl-encryption/)

  •    Verified the classpath was pointing to the sql driver jar file
    
  •    Verified that the classpath was pointing to the file jsse.jar located in the jre/lib folder
    

(As shown in: https://blogs.msdn.microsoft.com/jdbcteam/2008/09/09/the-driver-could-not-establish-a-secure-connection-to-sql-server-by-using-secure-sockets-layer-ssl-encryption/)

  • Updated the Java JDK to version 1.8.0_191 from 1.8.0_121

Doing all those things above failed to resolve the issue. Then there are the options listed in this article:

https://blogs.msdn.microsoft.com/dataaccesstechnologies/2016/11/30/intermittent-jdbc-connectivity-issue-the-driver-could-not-establish-a-secure-connection-to-sql-server-by-using-secure-sockets-layer-ssl-encryption-error-sql-server-returned-an-incomplete-respons/

I tried option 1 in the article, which was to update the driver. I question whether I should try options 2 through 4 in the article without producing some adverse effect.

Thank you for your help.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
shaldipurcommented, Nov 29, 2018

It looks like the Tomcat was not pointing to the same JDK version that the system was pointed to (in environment variables). Once those were set to the same version everything started working again. We’l monitor the performance and if it fails again we’ll begin investigating the Certificate Authorities as well. Thank you both for your help.

0reactions
jardelnovaescommented, Nov 29, 2018

Hello @shaldipur

About the error “Also we get the following error when trying to connect to the database via our IDE”: It seems that you are forgetting some configuration when you are runnig it by the IDE.

Each certificate (a valid one, not a self-signed) has a path, the final level is your certificate and the above levels are CAs (Certificate Authorities)

“find valid certification path to requested target” means that your certificate doesn’t have a valid path (Are the CA’s in the cetificate path? How many levels does your certificate has?). This problem can be in the client or in the server, so you need to check:

Your client side: The client certificate has the full path (Certificate and CAs), you can import it with Microsoft Egde to check it or use some keystore app. You can try import it with Microsoft Egde and export it with all path, sometimes this exported certificate works. (Don’t forget to mark export option when you are importing it)

You should get the server certificate to check some issues.

Does your /jre/bin/security/cacerts has the server’s CAs inside? To trust in CAs using Java you usually need to have the CA’s in the cacerts. (Default password is “changeit”, it´s a .jks file)

If you are using a different “cacerts”(trustCerts) you should tell it to Java, example:

-Djavax.net.ssl.trustStore="$JAVA_HOME/jre/lib/security/cacerts"
-Djavax.net.ssl.trustStorePassword="changeit"

Have you ever check the antivirus? It’s uncommon, but I’ve already seen it.

Are you using a self-signed certificate? It’s not a good idea, but if you really need this approach you’ll need to add the full certificate in the cacerts and not just the CAs.

Have you ever check the HTTPS protocol supported by server and the client? You can limit the protocols using:

-Dhttps.protocols=TLSv1.1,TLSv1.2

For a full analysis you can debug the SSL connection using:

-Djavax.net.debug=all

It’ll take some hours to understand the problem, but it’s the full net layer log.

Your server side:

Did you server relies on the client certificate? you should make the same checks on the server side.

Have you ever try to use a not security connection? If you problem is certificates or CAs using a not SSL connection will work fine. Just a test.

About “java.lang.ClassNotFoundException: Could not load requested class : com.microsoft.sqlserver.jdbc.SQLServerDriver” It seems you really don’t have the driver “loaded”, I don’t now if your webcontainer discards this dependency if has some problem, maybe the certificate problem is related with this one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling errors - JDBC Driver for SQL Server | Microsoft Learn
When using the Microsoft JDBC Driver for SQL Server, all database error conditions are returned to your Java application as exceptions using ...
Read more >
Why is the JDBC connection failing for SQL Server? - Forums
For testing I have downloaded the Jdbs driver, but it gives the error:KQZ0262E The server connection was not successful: Cannot open database "server\instance" ......
Read more >
SQL Server JDBC Driver failure · Issue #889 - GitHub
Actual behaviour: The JDBC driver fails to establish a connection to our database when deployed to our development server. ... We suspect the ......
Read more >
com.microsoft.sqlserver.jdbc.SQLServerDriver not found error
You dont need both jTDS and JDBC in your classpath. Any one is required. Here you need only sqljdbc.jar . Also, I would...
Read more >
SQL Server JDBC Error: The TCP/IP connection to the host ...
If you are getting this error after installing SQL SERVER 2012 or 2014 while first time trying to connect from Java program using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found