Sidebar

Can I create and use an H2 database from a channel in QIE

0 votes
801 views
asked Apr 20, 2016 by brandon-w-8204 (33,170 points)

1 Answer

+1 vote

1. Create a database connection to set the location and login information:

Name = desired name of the connection
Username = not required
Password = not required
Path = /tmp will work on Windows or Linux
Schema = name of the database

2. Create a Mapping to create the table if it does not exist

var dbName = 'H2 Test DB';

var query = "CREATE TABLE IF NOT EXISTS test_table (\n" +

   "field1 VARCHAR(255) PRIMARY KEY, \n" +

   "field2 VARCHAR(255), \n" +

   "field3 timestamp)";

qie.doQuery(dbName, query, false);

3. Create a mapping to insert rows in the table. (DB file is created on first update if it does not exist.)

var dbName = 'H2 Test DB';

var query = "INSERT INTO test_table \n" +

   "(field1, field2, field3)\n" +

   "VALUES('data1', 'data2', '{SYSTEM_DATE[yyyy-MM-dd HH:mm:ss]}')";

qie.doQuery(dbName, query, false);

Please Note: This database is not managed by QIE and will not be cleaned up as messages are cleaned up. Make sure you have something to manage records in this database to avoid running out of disk space.

answered Apr 20, 2016 by brandon-w-8204 (33,170 points)
edited Oct 10, 2017 by michael-h-5027
...