Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The H2 in-memory database stores data in memory inside the JVM. When the JVM exits, this data is lost. </p> <p>I suspect that what you are doing is similar to the two Java classes below. One of these classes creates a table and the other tries to insert into it:</p> <pre><code>import java.sql.*; public class CreateTable { public static void main(String[] args) throws Exception { DriverManager.registerDriver(new org.h2.Driver()); Connection c = DriverManager.getConnection("jdbc:h2:mem:test"); PreparedStatement stmt = c.prepareStatement("CREATE TABLE PERSON (ID INT PRIMARY KEY, FIRSTNAME VARCHAR(64), LASTNAME VARCHAR(64))"); stmt.execute(); stmt.close(); c.close(); } } </code></pre> <p>and</p> <pre><code>import java.sql.*; public class InsertIntoTable { public static void main(String[] args) throws Exception { DriverManager.registerDriver(new org.h2.Driver()); Connection c = DriverManager.getConnection("jdbc:h2:mem:test"); PreparedStatement stmt = c.prepareStatement("INSERT INTO PERSON (ID, FIRSTNAME, LASTNAME) VALUES (1, 'John', 'Doe')"); stmt.execute(); stmt.close(); c.close(); } } </code></pre> <p>When I ran these classes one after the other, I got the following output:</p> <pre> C:\Users\Luke\stuff>java CreateTable C:\Users\Luke\stuff>java InsertIntoTable Exception in thread "main" org.h2.jdbc.JdbcSQLException: Table "PERSON" not found; SQL statement: INSERT INTO PERSON (ID, FIRSTNAME, LASTNAME) VALUES (1, 'John', 'Doe') [42102-154] at org.h2.message.DbException.getJdbcSQLException(DbException.java:327) at org.h2.message.DbException.get(DbException.java:167) at org.h2.message.DbException.get(DbException.java:144) ... </pre> <p>As soon as the first <code>java</code> process exits, the table created by <code>CreateTable</code> no longer exists. So, when the InsertIntoTable class comes along, there's no table for it to insert into.</p> <p>When I changed the connection strings to <code>jdbc:h2:test</code>, I found that there was no such error. I also found that a file <code>test.h2.db</code> had appeared. This was where H2 had put the table, and since it had been stored on disk, the table was still there for the InsertIntoTable class to find.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload