Search in sources :

Example 1 with JdbcConnectionPool

use of org.h2.jdbcx.JdbcConnectionPool in project ignite by apache.

the class DbH2ServerStartup method main.

/**
     * Start H2 database TCP server.
     *
     * @param args Command line arguments, none required.
     * @throws IgniteException If start H2 database TCP server failed.
     */
public static void main(String[] args) throws IgniteException {
    try {
        // Start H2 database TCP server in order to access sample in-memory database from other processes.
        Server.createTcpServer("-tcpDaemon").start();
        populateDatabase();
        // Try to connect to database TCP server.
        JdbcConnectionPool dataSrc = JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", "");
        // Create Person table in database.
        RunScript.execute(dataSrc.getConnection(), new StringReader(CREATE_PERSON_TABLE));
        // Populates Person table with sample data in database.
        RunScript.execute(dataSrc.getConnection(), new StringReader(POPULATE_PERSON_TABLE));
    } catch (SQLException e) {
        throw new IgniteException("Failed to start database TCP server", e);
    }
    try {
        do {
            System.out.println("Type 'q' and press 'Enter' to stop H2 TCP server...");
        } while ('q' != System.in.read());
    } catch (IOException ignored) {
    // No-op.
    }
}
Also used : JdbcConnectionPool(org.h2.jdbcx.JdbcConnectionPool) SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) StringReader(java.io.StringReader) IOException(java.io.IOException)

Example 2 with JdbcConnectionPool

use of org.h2.jdbcx.JdbcConnectionPool in project ignite by apache.

the class DbH2ServerStartup method populateDatabase.

/**
     * Populate sample database.
     *
     * @throws SQLException if
     */
public static void populateDatabase() throws SQLException {
    // Try to connect to database TCP server.
    JdbcConnectionPool dataSrc = JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", "");
    // Create Person table in database.
    RunScript.execute(dataSrc.getConnection(), new StringReader(CREATE_PERSON_TABLE));
    // Populates Person table with sample data in database.
    RunScript.execute(dataSrc.getConnection(), new StringReader(POPULATE_PERSON_TABLE));
}
Also used : JdbcConnectionPool(org.h2.jdbcx.JdbcConnectionPool) StringReader(java.io.StringReader)

Aggregations

StringReader (java.io.StringReader)2 JdbcConnectionPool (org.h2.jdbcx.JdbcConnectionPool)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 IgniteException (org.apache.ignite.IgniteException)1