How to connect to the play framework in memory database using JDBC?

When I have DB = MEM in the configuration file, I use the memory database attached to the play framework for development

How do I connect to this database using JDBC? Instead of the default JPA

I tried this method in my controller:

public static void addToDB() {
    try {
        Connection conn = DriverManager.getConnection("jdbc:h2:mem:play");
        Statement stmt = conn.createStatement();
        stmt.execute(sql);
        stmt.close();
        conn.close();
    } catch (sqlException e) {
        e.printStackTrace();
    }
}

But I received an error message. I need to provide user name and password:

org.h2.jdbc.JdbcsqlException: Wrong user name or password [8004-149]

If I access the web console on / @ dB, I use the user name SA and have no password

Now I log in through the / @ DB interface and create a table user

Then I connect to the database in a controller method and use this JDBC string: JDBC: H2: MEM: Play: SA, and then try to insert the table user, but I receive this error message:

org.h2.jdbc.JdbcsqlException: Table "USERS" not found; sql statement:

How should I use JDBC to connect to an in memory H2 database in the play framework?

Solution

DB. Getconnection(), what should be done

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>