Spring Boot Hikari can't find DriverClassName - java

I have a spring boot project,It run just fine when I execute via eclipse Project > Run as > spring boot app
but when I build the project and execute it using java -jar myproject.jar or run it using mvn spring-boot:run it throw this error
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driverclassname
Value: com.microsoft.sqlserver.jdbc.SQLServerDriver
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class com.microsoft.sqlserver.jdbc
.SQLServerDriver in either of HikariConfig class loader or Thread context classloader
Action:
Update your application's configuration
my sql server connector dependency
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.4.0.jre8</version>
<scope>test</scope>
</dependency>
and here my application.properties
spring.datasource.url=jdbc:sqlserver://mydb;databaseName=HTSdb
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
it looks my app can't find the sqlserver driver but it is already in project classpath,any suggestion? thanks in advance

I think the issue is with dependency scope which is set as test.
Scope test indicates that dependency isn't required at standard runtime of application and should only be used for purpose of test runs only!
Usually database connectors dependency are set with runtime scope.
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.4.0.jre8</version>
<scope>runtime</scope>
</dependency>

Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driver-class-name
Value: org.postgresql.Driver
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class org.postgresql.Driver in either of HikariConfig
class loader or Thread context classloader
Action:
Update your application's configuration
Just had the same error, in my case with "org.postgresql.Driver".
Gues what was the issue? an empty space after "org.postgresql.Driver " by mistake.
So, be aware about that ' ' invisible empty space :).

Add dependency
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
check if Jar is loaded in lib if not then you need to add version 8.2.1.jre8 and rebuild the project .
You can validate by checking if mssql-jdbc-8.2.1.jre8 jar is there loaded in project and it has SQLServerDriver.class file in it .

Related

Connect to MSSQL v18 from Spring boot application using windows authentication

I am currently using the below properties to connect to localhost from Java spring boot application:
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:sqlserver://localhost:1433;database=vlad;integratedSecurity=true
spring.jpa.properties.hibernate.format_sql=true
springdoc.api-docs.path=/api-docs
From Java spring boot this is not working. The error I get is:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
You will most likely need to configure your Dialect and Include a driver:
application.properties:
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2016Dialect
You will also most likely need to add driver and auth dependency to your pom.xml
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc_auth</artifactId>
<version>10.2.1.x86</version>
<type>dll</type>
</dependency>
If that doesn't do the trick, you might have to manually download the Driver:
https://learn.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-2017
Hope it helps

How to set up IRIS database with Quarkus

I'm trying to use Intersystems IRIS Database with
Quarkus, but I'm getting problems making it work
does anyone knows how to set up the Intersystems IRIS Database
on Quarkus ?
I did that on my pom.xml and also I added the jar
hibernate-iris-1.0.0.jar and intersystems-jdbc-3.2.0.jar but it's not working
<dependency>
<groupId>com.intersystems</groupId>
<artifactId>intersystems-jdbc</artifactId>
<version>3.2.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/intersystems-jdbc-3.2.0.jar</systemPath>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-iris</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/hibernate-iris-1.0.0.jar</systemPath>
</dependency>
This is my application.properties
quarkus:
datasource:
db-kind: other
username: _system
password: *****
jdbc:
url: jdbc:IRIS://localhost:1972/USER
driver: com.intersystems.jdbc.IRISDriver
hibernate-orm:
dialect: org.hibernate.dialect.InterSystemsIRISDialect
jdbc:
timezone: UTC
I found the solution, to set up Intersystems IRIS on Quarkus you need to add manually the jar file, and also you need to set up the pom.xml also some setup from Intersystems was made as a java class. you can see the solution looking at my project on GitHub
this is the link: https://github.com/JoseAdemar/quarkus-project-with-intersystems-ris-database

Failed to bind properties under 'spring.ora-datasource' to javax.sql.DataSource:

I'm getting failed when compilling app
spring.ora-datasource.username=root
spring.ora-datasource.password=root
spring.ora-datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.ora-datasource.maximumPoolSize=2
my oracle dependency
<!--Oracle-->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
</dependency>
Error
Failed to bind properties under 'spring.ora-datasource' to javax.sql.DataSource:
Property: spring.ora-datasource.driver-class-name
Value: oracle.jdbc.driver.OracleDriver
Origin: class path resource [application.properties]:11:41
Reason: Failed to load driver class oracle.jdbc.driver.OracleDriver in either of HikariConfig class loader or Thread context classloader
Action:
Update your application's configuration
Try spring.ora-datasource.driver-class-name=oracle.jdbc.OracleDriver
Note the package name.

Liquibase maven plugin is not using classpath property

For some reason the Liquibase maven plugin is not using my property when I set it in my liquibase.properties file. When I run mvn liquibase:update I get the following INFO.
[INFO] there are no resolved artifacts for the Maven project.
[INFO] Parsing Liquibase Properties File
[INFO] File: target/classes/liquibase.properties
[INFO] 'classpath' in properties file is not being used by this task.
Due to this, the update fails as liquibase can't find the driver and can't connect to the database.
I saw this SO question but they are using the liquibase executable and not maven. I used it as an example on how to use the liquibase.properties file.
Setting up Liquibase with MS-SQL Server
I see where it is hitting an exception L571 to L588 the exception but the actual exception isn't printed out so I don't know the cause of the error.
https://github.com/liquibase/liquibase/blob/9ae7f90a0bbbbcec229a0788afa74831db348ced/liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/AbstractLiquibaseMojo.java#L573
Rather than setting the classpath in a properties file, you must put the driver jar as a dependency in your maven POM.
See the documentation for the Liquibase Maven Task, and especially the section that describes different JDBC dependencies. Here's a snippet:
Example of Maven Liquibase Update
You need to ensure that you include the relevant JDBC driver for your
database in the dependency section of Maven POM file.
MySQL example:
<project>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<!-- Replace with the version of the MySQL driver you want to use -->
<version>${mysql-version}</version>
</dependency>
</dependencies>
</project>
In my case it was a simple copy and paste issue.
The property driver in liquibase.properties ends with a space. after deleting the space everything was fine.
driver: com.mysql.cj.jdbc.Driver
vs
driver: com.mysql.cj.jdbc.Driver
This answer put me in the right direction. In my case, it was that I needed to declare the Maven resource.
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
Hope it helps!

Spring Boot Unable to load class: com.microsoft.sqlserver.jdbc.SQLServerDriver

I've created a new Spring Boot project. I'm trying to setup a DataSource to use MSSQL. However I seem to be getting the error "Unable to load class: com.microsoft.sqlserver.jdbc.SQLServerDriver"
I've placed the file jdbcsql4.jar in a folder in my project /lib/jdbcsq4.jar
In my pom.xml file I've added the following:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
<scope>system</scope>
<optional>true</optional>
<systemPath>${basedir}/lib/sqljdbc4.jar</systemPath>
</dependency>
I have an application.properties file, and I'm defining the database credentials like this:
secondary.datasource.url = jdbc:sqlserver://1.1.1.1:50109
secondary.datasource.username = sa
secondary.datasource.password = mypassword
secondary.datasource.driver-class-name = com.microsoft.sqlserver.jdbc.SQLServerDriver
Can anyone possibly indicate where I may be going wrong?
I managed to solve this issue by following the instructions in this link http://claude.betancourt.us/add-microsoft-sql-jdbc-driver-to-maven/
EDIT:
The original link above no longer exists, but here's a similar link.
http://biercoff.com/add-microsoft-sql-jdbc-driver-to-maven/
For the ppl who facing these issue.
Add dependency in POM.
Microsoft finally made the driver available on the Maven Central Repository.
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
you can check here.
Microsoft link

Categories

Resources