I'm having a little problem making simple CRUD application in JavaFX using Maven and H2 Database. I've created a database (which .db file is located at Users direction by default) and I've problem with connected my Java project with this file. My database file (data.mv.db) is located in default directory so URL of JBDC is absolutely correct.
It looks like the DBConnection class isn't seeing my .db file, I don't know why.
When I'm running a DBConnection class IDE's putting out SQLException:
java.sql.SQLException: No suitable driver found for jdbc:h2:~/data
Here is my DBConnection class code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConnection {
public static void main(String[] args) {
String jdbcURL = "jdbc:h2:~/data";
String username = "sa";
String password = "123";
try {
Connection connection = DriverManager.getConnection(jdbcURL, username, password);
System.out.println("Connected to H2 embedded database.");
connection.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
}
H2 Database library is added to my project by dependency in Maven. Here is dependency in pom.xml file:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.220</version>
<scope>test</scope>
</dependency>