SQL Server JDBC Driver failure
See original GitHub issueDriver 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
- 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.
- Actual behaviour:
The JDBC driver fails to establish a connection to our database when deployed to our development server.
- 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.
- 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
-
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
- 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:
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:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
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.
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:
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:
For a full analysis you can debug the SSL connection using:
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.