B4J Question MSSQL DRIVER Issue

Peter Lewis

Active Member
Licensed User
Longtime User
Hi, I have the following additional jar
B4X:
#AdditionalJar:mssql-jdbc-12.8.2.jre11
#AdditionalJar: HikariCP-5.0.1
then I am using Java jdk-19.0.2
To init the pool we are using

B4X:
Public pool As HikariCP
pool.Initialize("com.microsoft.sqlserver.jdbc.SQLServerDriver",$"jdbc:sqlserver://${host}:${port};databaseName=${database}"$,user,password)

with the following code starting sql

B4X:
Dim sql As SQL = pool.GetConnection

The error code I am getting is as follows

java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=com.microsoft.sqlserver.jdbc.SQLServerDriver

The .jar file is in the additional files folder and I cannot see what I have done wrong.

Thank you
 

besoft

Active Member
Licensed User
Longtime User
Try this:

string:
pool.Initialize("com.microsoft.sqlserver.jdbc.SQLServerDriver", _
    $"jdbc:sqlserver://$host$:$port$;databaseName=$database$;encrypt=true;trustServerCertificate=true"$, _
    user, password)

Newer mssql-jdbc drivers have encryption enabled by default, and if the certificate is not trusted, the connection fails (sometimes it shows as "Failed to get driver instance..." or as an SSL error, depending on where the exception is caught).
 
Upvote 0
Top