I am creating a simple app to experiment with the hsqldb database, but i cant even start because my IDE giving me an exeption
"Cannot load driver class: org.hsqldb.jdbc.JDBCDriver"
I've researched this problem, but i didnt find the solution.
I am using Sprint tool suit 4.4 as my IDE.
This is my application.properties
file:
spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver
spring.datasource.url=jdbc:hsqldb:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
This is my pom.xml
(i have added more than i need, i thought that maybe the problem is "not enough dependencies"):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.32.3.2</version>
</dependency>
<!-- Derby DB -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>${derby.version}</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.2</version>
<scope>test</scope>
</dependency>
I also tried to change the version of hsqldb dependency but i didnt work.
This is my simple dao class:
@Transactional
@Repository
public class ProductDaoImpl implements ProductDao {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public List<Product> getAllProducts() {
String query = "SELECT * from products";
RowMapper<Product> rowMapper = new ProductRowMapper();
List<Product> list = jdbcTemplate.query(query, rowMapper);
return list;
}
@Override
public void addProduct(Product product) {
String query = "INSERT INTO products(id, name) VALUES(?, ?)";
jdbcTemplate.update(query, product.getId(), product.getName());
}
}
I also checked the class path of the driver, and it is in place. I cant imagine what i am doing wrong.
Remove the <scope>test</scope>
from the dependency. You are not using the hsqldb for tests only.
Also, the spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver
is redundant, since the driver is part of the datasource url.