Jump to content

[1.12.2] How to use H2 Driver?


ratquaza

Recommended Posts

Currently trying to add H2 Database support with my mod. I've shaded the h2 database engine in my build.gradle like so:

shadowJar {
    dependencies {
        include dependency("org.json:json:20180813"),
        include dependency("com.h2database:h2:1.0.60")
    }
    relocate("org.json", "shaded.org.json")
    relocate("com.h2database","shaded.com.h2database")
}

...
  
reobf {
    shadowJar {
        mappingType = 'SEARGE'
    }
}

 

Issue is, everytime I attempt to establish a connection using my H2Connection class like so:

H2Connection db = new H2Connection("jdbc:h2:D:/H2db/test/test", "admin", "password");

 

I get an error saying: java.sql.SQLException: No suitable driver found for jdbc:h2:D:/H2db/test/test

Anyone know whats up? Am I doing this right?

 

This is my H2Connectionclass:

public class H2Connection {
    private Connection conn;

    public H2Connection() {}
    public H2Connection(String url, String user, String pass) throws SQLException, ClassNotFoundException {
        connect(url, user, pass);
    }
    public void connect(String url, String user, String pass) throws SQLException, ClassNotFoundException {
        conn = DriverManager.getConnection(url,user,pass);
    }
    public ResultSet query(String query) throws SQLException {
        return conn.createStatement().executeQuery(query);
    }
}

 

Edited by ratquaza
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.