Reputation: 13
Can't connect to database.
I also added the latest h2-1.4.178.jar
to classpath, create table, check connection through tools.
It's working, but Tomcat said: "HTTP Status 500 - com.vaadin.server.ServiceException: java.lang.RuntimeException: Specified JDBC Driver: org.h2.jdbc - initialization failed."
How can I call it? I use Eclipse. This is my src (I use Vaadin):
try {
JDBCConnectionPool pool = new SimpleJDBCConnectionPool(
"org.h2.jdbc",
"jdbc:h2:~test", "SA", "", 2, 5);
screen.polulate("TEST", pool);
} catch (SQLException e) {
throw new RuntimeException(e);
}
I found my problem (https://superuser.com/questions/290999/where-can-i-find-h2-jdbc-driver), but i cant understand what does it mean:
And then call
Class.forName("org.h2.Driver");
Upvotes: 1
Views: 2437
Reputation: 109146
The answer you link to is not really relevant to your problem. The problem probably (educated guess) is that the first parameter of the constructor of SimpleJDBCConnectionPool
expects the JDBC driver name, and "org.h2.jdbc"
is not the JDBC driver name (it's "org.h2.Driver"
).
Using Class.forName("org.h2.Driver");
is no longer necessary for modern JDBC drivers. With old drivers (that don't include a file META-INF/services/java.sql.Driver
with its driver implementation(s)) using Class.forName("org.h2.Driver");
will load the driver and then the driver will register itself with java.sql.DriverManager
so it can be used to create connections.
Upvotes: 1