I load a JDBC driver class using Class.forName("org.h2.Driver")
in my Global
object. (The reason for this is because I am accessing two databases, which use different JDBC drivers, and one of them is not configured in my application.conf
file.)
However, when I change a source file in my project (which makes Play recompile and reload the project), I get the following runtime error in my Global object:
java.sql.SQLException: No suitable driver found for jdbc:h2:mem:...
This doesn't happen the first time the application is run, only after a reload.
How can I fix this?
I just needed to add a config for my second database in application.conf
, and obtain it by calling the overloaded getConnection
and withConnection
methods in DB
which take a database name as an argument. Then I could remove Class.forName
, which solved the problem.