Use the following example to find out 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 {
// Log on to the database instance
session.cmd ("use serverdb TST");
session.cmd ("use user TESTUSER TEST");
// Create a table 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 {
// End the connection to the Loader
session.release ();
}
catch (RTEException rteExc) {
// ignore
}
}
}
}