ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ravi <ravikumarpur...@gmail.com>
Subject Alternate way of using DBH2ServerStartup ??
Date Mon, 18 Jan 2016 05:22:40 GMT
/**
 * Start H2 database TCP server in order to access sample in-memory database
from other processes.
 */
public class DbH2ServerStartup {
    /** Create table script. */
    private static final String CREATE_PERSON_TABLE =
        "create table if not exists PERSON(id bigint not null, first_name
varchar(50), last_name varchar(50), PRIMARY KEY(id));";

    /** Sample data script. */
    private static final String POPULATE_PERSON_TABLE =
        "delete from PERSON;\n" +
        "insert into PERSON(id, first_name, last_name) values(1, 'Johannes',
'Kepler');\n" +
        "insert into PERSON(id, first_name, last_name) values(2, 'Galileo',
'Galilei');\n" +
        "insert into PERSON(id, first_name, last_name) values(3, 'Henry',
'More');\n" +
        "insert into PERSON(id, first_name, last_name) values(4, 'Polish',
'Brethren');\n" +
        "insert into PERSON(id, first_name, last_name) values(5, 'Robert',
'Boyle');\n" +
        "insert into PERSON(id, first_name, last_name) values(6, 'Wilhelm',
'Leibniz');";

    /**
     * Populate sample database.
     *
     * @throws SQLException if
     */
    public static void populateDatabase() throws SQLException {
        // Try to connect to database TCP server.
        JdbcConnectionPool dataSrc =
JdbcConnectionPool.create("jdbc:mysql://172.17.125.19/security_sample",
"coeuser", "CoeUser@2014");

        // 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));
    }

    /**
     * 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:mysql://172.17.125.19/security_sample",
"coeuser", "CoeUser@2014");

            // 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.
        }
    }
}


DbH2ServerStartup  class is compulsory need to start the server of TCP/Ip
needed to query the examples. But if i wat to query the example form mysql
databse without starting the DBH2 server. How can i do this?



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Alternate-way-of-using-DBH2ServerStartup-tp2599.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Mime
View raw message