Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to detect database type

I'm trying to create a Spring Boot application using sqljdbc4 driver with this config:

spring:
  datasource:
    url: "jdbc:sqlserver://dbhost:1433;databaseName=test"
    username: dbuser
    password: dbuser
    tomcat:
      test-on-borrow: true
      validation-query: select 1

But, when I run, I get this error: Unable to detect database type

I was debugging BatchDatabaseInitializer, where error came from, and when it calls JdbcUtils.commonDatabaseName(...), "Microsoft SQL Server" is returned as product name that doesn't match with any DatabaseDriver's product name.

I tried other drivers but they all have the same problem.

Is it a bug?

I'm using Spring Boot 1.5.1-RELEASE.

like image 455
Marcus Henrique Avatar asked Apr 23 '26 12:04

Marcus Henrique


1 Answers

You need to properly configure your spring.datasource config in application.properties file if you're using spring-batch to create batch jobs. Below is mine ->

spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/batch_repo
spring.datasource.username=batch_username
spring.datasource.password=batch_password
spring.datasource.platform=mysql

spring.batch.initialize-schema=always

spring.batch.initialize-schema when configured to "always", will create the necessary spring batch related tables in your schema.

Alternatively, if you assign it to "never", it will refrain from creating the tables. In both these cases your error should get resolved.

like image 195
Uchiha Suryajit Avatar answered Apr 26 '26 14:04

Uchiha Suryajit