Examples
The code listings in this section are adapted from the api-helper-example.mon application. The actual code can be found in the Apama installation’s samples\adbc\api-helper-example directory.
Opening and closing a database and executing SQL commands
monitor ADBCHelper_Example
{
com.apama.database.DBUtil db;
action onload {
db.openQuickODBC( "MySQL", "fred", "fred-123", handleError );
db.doSQLCmd( "insert into NetworkInformation values (
'Vodafone', 'FR', 104 );");
db.doSQLCmd( "insert into NetworkInformation values (
'O2', 'FR', 101 );");
db.doSQLCmd( "insert into NetworkInformation values (
'Three', 'FR', 102 );");
db.doSQLCmdAck( "insert into NetworkInformation values (
'Orange', 'FR', 103 );", 100, false);
com.apama.database.DBAcknowledge ack;
on com.apama.database.DBAcknowledge(ackNum = 100) : ack {
if ack.error.length() = 0 then {
log "Action complete" at INFO;
// Other success handling code ...
}
else {
log "Action failed: " + ack.error at ERROR;
// Other failure handling code ...
}
db.close( false);
}
action handleError( string reason ) {
log "DB Error: " + reason at ERROR;
}
}
Executing SQL queries
monitor ADBCHelper_Example
{
com.apama.database.DBUtil db;
action onload {
db.openQuickODBC( "DBName", "user", "password", handleError );
db.doSQLQuery(
"SELECT * FROM NetworkInformation", handleResult );
db.close( false);
}
action handleResult( dictionary< string, string > data ) {
log "Network: " + data[ "network" ] +
" CountryCode: " + data[ "countrycode" ] +
" NIC: " + data[ "networkidentificationcode" ] at INFO;
}
action handleError( string reason ) {
log "DB Error: " + reason at ERROR;
}
}
Copyright © 2013
Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.