Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
    
 Derby - Class org.apache.derbyDemo.vtis.core.VTIHelper
    
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at
    
 http://www.apache.org/licenses/LICENSE-2.0
    
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
    
 */

import java.sql.*;

public class Main {
    private static final boolean DEBUG = true;

    /**
     * <p>
     * Execute a DDL statement
     * </p>
     */
    public static void executeDDL(String ddl) throws SQLException {
        Connection conn = getLocalConnection();

        // now register the function
        print(ddl);
        try {
            PreparedStatement createStatement = conn.prepareStatement(ddl);

            createStatement.execute();
            createStatement.close();
        } catch (SQLException t) {
            SQLException s = new SQLException("Could not execute DDL:\n" + ddl);

            s.setNextException(t);

            throw s;
        }
    }

    /**
     * <p>
     * Get the connection to the local database.
     * </p>
     */
    public static Connection getLocalConnection() throws SQLException {
        return DriverManager.getConnection("jdbc:default:connection");
    }

    /**
     * <p>
     * Debug helper method to print a diagnostic.
     * </p>
     */
    public static void print(String text) {
        if (DEBUG) {
            System.out.println(text);
        }
    }
}