Integration Server 10.3 | WmDB User’s Guide | Accessing Databases with Services | Creating Clients that Access Databases | Invoking a Built-in Service from a Java, C/C++, or VB Client
 
Invoking a Built-in Service from a Java, C/C++, or VB Client
You can create client applications in Java or C/C++. The client applications can use the built-in database services to perform database operations. For information about these built-in services, see the webMethods Integration Server Built-In Services Reference.
If you want your client to access a database that has nonstandard features (for example, data types that are not supported by SQL), you use other database APIs. For example, you can make direct calls to JDBC or use other connection libraries, such as ADO.
Sample Code - IData
The following shows a sample Java client that accesses a database using an IData object to pass and receive data from the database service.
import com.wm.data.*;
import com.wm.app.b2b.client.Context;
 
public class DBClient
{
public static void main (String [] args) throws Exception
{
IData in = null;
IData out = null;
IData criteria = null;
IData set = null;
 
//
// connect to your integration server using an appropriate user
// name and password (doesn't have to be Administrator)
//
Context ctx = new Context();
ctx.connect ("localhost:5555", "Administrator", "manage");
//
// (1) request a DB connection by DB alias (if the DB
// changes location or something, we won't have to change
// this client code)
//
in = IDataFactory.create();
IDataCursor inCursor = in.getCursor();
inCursor.insertAfter ("$dbAlias", "Employees");
inCursor.destroy();
out = ctx.invoke ("wm.util.db", "connect", in);
//
// (2) update the Identification table to set Fonz's ID
// to 6500. note that we couldn't do this from a Web
// browser because we couldn't build up the complex
// nested data structures
in = IDataFactory.create();
inCursor = in.getCursor();
inCursor.insertAfter ("$dbAlias", "Employees");
inCursor.insertAfter ("$dbTable", "Identification");
criteria = IDataFactory.create();
IDataCursor criteriaCursor = criteria.getCursor();
criteriaCursor.insertAfter ("name", "fonzie");
criteriaCursor.destroy();
inCursor.insertAfter ("$criteria", criteria);
set = IDataFactory.create();
IDataCursor setCursor = set.getCursor();
setCursor.insertAfter ("ID", "6500");
setCursor.destroy();
inCursor.insertAfter ("$set", set);
inCursor.destroy();
 
try {
out = ctx.invoke ("wm.util.db", "update", in);
 
//
// (3) look at the return values (updateCount is the
// most important in this case)
//
IDataCursor outCursor = out.getCursor();
 
if (outCursor.first("updateCount"))
{
int uc = Integer.parseInt ((String)outCursor.getValue());
System.err.println ("Update count: "+uc);
}
else
System.err.println ("Error: no update count returned");
outCursor.destroy();
} catch (Exception e) {
// maybe something went wrong with the DB access; we
// can get more information here
if (outCursor.first("$error")) {
System.err.println ("Error: "+outCursor.getValue());
}
if (outCursor.first("$errorType")) {
System.err.println ("Error type: "+outCursor.getValue());
}
outCursor.destroy();
}
}
 
}