Entering content frame

This graphic is explained in the accompanying text Example for Creating a Table with Java Locate the document in the library structure

This example illustrates how to connect to the database system with the Java interface. It then shows you how to use an SQL statement supported by the Loader to create a table, and how to end the connection with the Loader. 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 LoaderDemo

{

    public

    LoaderDemo ()

    {

    }

       public static void main(String[] args)

    {

 

        Loader session;

        try {

            // Connecting to the Loader

            session = Loader.dbLoader (null, null);

        }

        catch (RTEException rteExc) {

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

            return;

        }

        try {

              // Executing Loader Commands:

                              // Logging on to the database instance DEMODB

                            // as database user MONA with password RED

            session.cmd ("use serverdb DEMODB");

            session.cmd ("use user MONA RED");

              // Creating a table LOADERTEST with Java

            String result = session.cmd ("CREATE TABLE LOADERTEST ("

                + "TESTCOL VARCHAR (20) )");

            System.out.println(result);

        }

        catch (RTEException rteExc) {

            System.out.println ("connection broken: " + rteExc.toString ());

        }

        catch (LoaderException LoaderExc) {

            System.out.println ("command failed: " + LoaderExc.toString ());

        }

        finally {

try {

              // Ending the Connection to the Loader

                session.release ();

            }

            catch (RTEException rteExc) {

                // ignore

            }

        }

    }

}

 

Leaving content frame