Entering content frame

 Example for Displaying the Operational State of a Database 

Use the following example to find out 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 {

            // End the connection to Database Manager:

                         // Connect to the DBM Server of an existing database instance

            session = DBM.dbDBM (null, "TST");

        }

        catch (RTEException rteExc) {

            System.out.println ("connect failed: " + rteExc.toString ());

            return;

        }

        try {

            // Execute DBM commands

                          // Log on as a DBM operator

            session.cmd ("user_logon DBMUSER,DBM");

            // Display 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 {

                // End the connection to the Database Manager

                session.release ();

            }

            catch (RTEException rteExc) {

                // ignore

            }

        }

    }

}

 

Leaving content frame