Example: Displaying the Operational State of the Database Instance

This example shows how you display the operational state of the database instance in your Java application.

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 {

            // You connect to the DEMODB database.

                         //  see com.sap.dbtech.powertoys.DBM.dbDBM Method   

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

        }

        catch (RTEException rteExc) {

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

            return;

        }

        try {

                          // You log on as the DBM operator OLEG with the password MONDAY.

            // see com.sap.dbtech.powertoys.DBM.cmd Method

            session.cmd ("user_logon OLEG,MONDAY");

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

                // You then end the connection to the Database Manager.

                // see com.sap.dbtech.powertoys.DBM.release Method

                session.release();

            }

            catch (RTEException rteExc) {

                // ignore

            }

        }

    }

}

See also:

Database Manager Java Classes