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);
on com.apama.database.DBAcknowledge(ackNum = 100) as ack {
if ack.error.length() = 0 {
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;
}
}