Reputation: 3
I'd like to create a java file with a database.
Running a Maven build works but as soon as I add anything to application.properties it fails.
heres what I'm adding to the application.properties
spring.datasource.url=jdbc:sqlite:defaultdb.db
spring.datasource.driver-class-name=org.sqlite.JDBC
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLiteDialect
spring.jpa.hibernate.ddl-auto update
EDIT:
Here's the error:
-------------------------------------------------------------------------------
Test set: com.javabackendfinal.JavaBackendFinalApplicationTests
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 5.088 s <<< FAILURE! - in com.javabackendfinal.JavaBackendFinalApplicationTests
contextLoads(com.javabackendfinal.JavaBackendFinalApplicationTests) Time elapsed: 0.001 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: org.sqlite.JDBC
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: org.sqlite.JDBC
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: org.sqlite.JDBC
Caused by: java.lang.IllegalStateException: Cannot load driver class: org.sqlite.JDBC
Upvotes: 0
Views: 329
Reputation: 3945
Add this dependency in your pom.xml file. It should get rid of this error. Caused by: java.lang.IllegalStateException: Cannot load driver class: org.sqlite.JDBC
This shows that it's unable to find the required class file on the classpath.
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.27.2.1</version>
</dependency>
Upvotes: 1