Anfang des Inhaltsbereichs

Diese Grafik wird im zugehörigen Text erklärt Beispiel 1 Dokument im Navigationsbaum lokalisieren

Die Java-Klasse TableDef kann genutzt werden, um Ergebnisse verschiedener Spaltendefinitionen anzuzeigen (siehe UNICODE und SQL, Abschnitt UNICODE für Anwendungsdaten).

Definition TableDef

import java.sql.*;
/**
 *
 */
public class TableDef
{
    private Connection connection;
    /**
     * creates a new TableDef
     */
   public
    TableDef (
        String url)
    throws SQLException, ClassNotFoundException
    {
        // load class
        Class.forName ("com.sap.dbtech.jdbc.DriverSapDB");
        // create connection
        this.connection = DriverManager.getConnection(url,
            new java.util.Properties ());
        this.connection.setAutoCommit (false);
    }
    /**
     *
     */
    protected void
    createTable (
        String tableName,
        String createCommand)
    throws SQLException
    {
        String fullCommand = "CREATE TABLE " + tableName + " ("
            + createCommand + " )";
        Statement stmt = this.connection.createStatement ();
        stmt.execute (fullCommand);
    }
    /**
     *
     */
    protected void
    showTableDef (
        String tableName)
    throws SQLException
    {
        System.out.println ("Table: " + tableName); //#print
        DatabaseMetaData metaData = this.connection.getMetaData ();
        ResultSet tableColumns = metaData.getColumns(null,
           metaData.getUserName (), tableName, null);
        while (tableColumns.next ()) {
            String columnName = tableColumns.getString ("COLUMN_NAME");
            String typeName = tableColumns.getString ("TYPE_NAME");
            int colSize = tableColumns.getInt ("COLUMN_SIZE");
            System.out.println ("    " + columnName
                + ": " + typeName + " (" + colSize + ")"); //#print
         }
    }
    /**
     *
     */
    protected void
    close ()
    {
        try {
            this.connection.rollback ();
            this.connection.close ();
        }
        catch (SQLException sqlExc) {
                // ignore
        }
    }
    /**
     *
     */
    static protected String
    join (
        String [] args,
        int startIndex)
    {
         if (startIndex >= args.length) {
           return null;
        }
        StringBuffer result = new StringBuffer ();
        for (int i = startIndex; i < args.length; ++i) {
            result.append(args [i]);
            result.append (' ');
        }
        return result.toString();
    }
    /**
     * used when called form the command line
     */
    public static void main (String [] args)
    throws ClassNotFoundException
    {
        String url = args [0];
        String tableName = args [1];
        String createCommand = join (args, 2);
        TableDef tableDef = null;

        try {
           tableDef = new TableDef (url);
            if (createCommand != null) {
                tableDef.createTable (tableName, createCommand);
            }
            tableDef.showTableDef (tableName);
        }
        catch (SQLException sqlExc) {
            System.out.println (sqlExc);
        }
        finally {
            if (tableDef != null) {
                 tableDef.close ();
            }
        }

    }
}

Ende des Inhaltsbereichs