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 {
session = Loader.dbLoader (null, null);
}
catch (RTEException rteExc) {
System.out.println ("connect failed: " + rteExc.toString ());
return;
}
try {
// 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
}
}
}
}