This example illustrates how to connect to the database instance with a Java interface. It then shows you how to execute the DBM command for displaying the operational state of the database instance, and how to end the connection to the Database Manager. The individual steps are listed in the comments in the example.
import com.sap.dbtech.powertoys.*;
import com.sap.dbtech.rte.comm.RTEException;
public class DBMDemo
{
public
DBMDemo ()
{
}
public static void main(String[] args)
{
DBM session;
try {
// Connecting to the database instance DEMODB
// Connection to an Existing Database Instance
session = DBM.dbDBM (null, "DEMODB");
}
catch (RTEException rteExc) {
System.out.println ("connect failed: " + rteExc.toString ());
return;
}
try {
// Logging on as DBM user OLEG with password MONDAY
session.cmd ("user_logon OLEG,MONDAY");
// Displaying the operational state of the database instance
String result = session.cmd ("db_state");
System.out.println(result);
}
catch (RTEException rteExc) {
System.out.println ("connection broken: " + rteExc.toString ());
}
catch (DBMException dbmExc) {
System.out.println ("command failed: " + dbmExc.toString ());
}
finally {
try {
// Ending the Connection to the Database Manager
session.release ();
}
catch (RTEException rteExc) {
// ignore
}
}
}
}