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
  • 12,050
  • 4
  • 30
  • 52

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
  • 658
  • 2
  • 9
  • 18
Thomas Mueller
  • 48,905
  • 14
  • 116
  • 132