You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Ravi <ra...@gmail.com> on 2016/01/18 06:22:40 UTC

Alternate way of using DBH2ServerStartup ??

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

Re: Alternate way of using DBH2ServerStartup ??

Posted by Ravi <ra...@gmail.com>.
thanx now its working.



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

Re: Alternate way of using DBH2ServerStartup ??

Posted by Alexey Kuznetsov <ak...@gridgain.com>.
Ravi,

You may use MySql, but in this case you will need to change data sources in
examples.
In examples data sources configured to use H2 database data source.
So you need:
 1) modify pom.xml - add dependency to MySql jdbc driver
 2) modify examples code - replace H2 data sources with MySql data sources
 3) start MySql, create tables and insert data using MySql tools
 4) start examples

Hope this help.


On Mon, Jan 18, 2016 at 12:22 PM, Ravi <ra...@gmail.com> wrote:

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



-- 
Alexey Kuznetsov
GridGain Systems
www.gridgain.com