Scripting Interfaces: General Host Objects
DBConnection:
Synopsis
Used to invoke DB queries using SQL statements. The result of the query is
converted to XML as follows
| Name | id |
| Tom | 12345001 |
| Mary | 12345002 |
| Richard | 12345006 |
is converted to
<result>
<record>
<Name>Tom</Name>
<id>12345001</id>
</record>
<record>
<Name>Mary</Name>
<id>12345002</id>
</record>
<record>
<Name>Richard</Name>
<id>12345006</id>
</record>
</result>
Use
Requires user to specify the connection string consisting of:
- Host / Port of the database daemon
- The database to connect to
- The username and password for authorization
dbconn = new DBConnection(
"jdbc:mysql://d-104-198.dhcp-156-56.indiana.edu/test?user=****&password=****"
);
xml = dbconn.runSQLQuery("SELECT * FROM empl");
Another way is to write the output to a specific stream as in the following example
dbconn = new DBConnection(
"jdbc:mysql://d-104-198.dhcp-156-56.indiana.edu/test?user=****&password=****"
);
dbconn.SQLQuery="SELECT id, name FROM empl";
r = new Resource();
r.port[0].publishTo("file:///u/hgadgil/test.xml");
r.port[0].subscribeFrom(dbconn.publish);
f = new Flow();
f.addComponents(r);
f.addStartActivities(dbconn);
f.start();
Status: Implemented
(back to Notes)