1

Can I connect to h2 embedded db without setting Class.forName("org.h2.Driver") ? I used only those parameters: url, login and pass

 public static Connection getConnection()  {
    String url= ResourseHelper.getUrl();
    String user= ResourseHelper.getUser();
    String pass= ResourseHelper.getPass();

    try {
        return DriverManager.getConnection(url, user, pass);
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return null;
}

And than I create embedded database using this connection. And it works. Is it correct?

too honest for this site
  • 11,797
  • 4
  • 29
  • 49

1 Answers1

2

Yes, for Java 1.6 and newer, Class.forName("org.h2.Driver") is no longer needed. This is due to a change in JDBC 4.0. For details, see Getting Connected Becomes Easier.

sebkur
  • 618
  • 2
  • 8
  • 18
Thomas Mueller
  • 47,133
  • 13
  • 106
  • 128