Background documentationExample: Exporting a Table Locate this document in the navigation structure

 

This example shows how to export a table in your Java application using Loader commands.

You proceed as follows:

  1. You call the Loader from your Java application.

  2. You connect to the Loader.

  3. You log on to the database.

  4. You export the table using a Loader command.

  5. You end the connection to the Loader.

The individual steps are listed in the comments in the example.

Syntax Syntax

  1. import com.sap.dbtech.powertoys.*;
    import com.sap.dbtech.rte.comm.RTEException;
    import java.util.Properties;
    
    public class LoaderDemo
    {
    	public
    	LoaderDemo ()
    	{
    	}
    
    	public static void main(String[] args)
    	{
    
    		// Loader mLoaderSession = null;
    		Loader mLoaderSession;
    		try {
    			// You connect to the Loader.
    			mLoaderSession = Loader.dbLoader(zero,zero);
    		}
    		catch (RTEException rteExc) {
    			System.out.println ("connect failed: " + rteExc.toString ());
    			return;
    		}
    		try {
    			// You log on as the database user MONA
    			// with the password RED
    			// to the database DEMODB.
    			// see com.sap.dbtech.powertoys.Loader.cmd Method
    			mLoaderSession.cmd ("use serverdb DEMODB");
    			mLoaderSession.cmd ("use user MONA RED");
    			// You export the LOADERTEST table
    			// using the cmd method
    			// and the Loader command EXPORT TABLE
    			// see EXPORT TABLE command
    			String result = mLoaderSession.cmd ("EXPORT TABLE HOTEL.CITY DATA OUTSTREAM FILE 'CITY.data'");
    			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 {
    				// You end the connection to the Loader.
    				// see com.sap.dbtech.powertoys.Loader.release Method
    				mLoaderSession.release ();
    			}
    			catch (RTEException rteExc) {
    				// ignore
    			}
    		}
    	}
    }
    
End of the code.