Java SQL Stored Procedure createTestProcedure()

Here you can find the source of createTestProcedure()

Description

create Test Procedure

License

Open Source License

Declaration

static void createTestProcedure() throws Exception 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from ww w . ja v  a 2  s  . c  o  m
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

import java.sql.DriverManager;

public class Main {
    /** Data types to be tested */
    final static String[] DATA_TYPES = new String[] { "decimal", "date", "float", "int", "varchar(100)", "time",
            "timestamp" };
    /** Test procedure name */
    final static String PROCEDURE_BASE_NAME = "testProc";

    static void createTestProcedure() throws Exception {
        java.sql.Connection jdbcConn = openJDBCConnection();

        String str = "";
        java.sql.Statement jdbcStmt = jdbcConn.createStatement();
        for (int i = 0; i < DATA_TYPES.length; i++) {
            str = "drop procedure" + PROCEDURE_BASE_NAME + i;
            try {
                jdbcStmt.execute(str);
            } catch (Exception e) {
            }

        }

        String str1 = "CREATE PROCEDURE ";
        String str2 = " PARAMETER STYLE JAVA READS SQL DATA LANGUAGE JAVA EXTERNAL NAME 'org.eclipse.birt.report.data.oda.jdbc.TestUtil.selectData'";
        String sql = "";

        for (int i = 0; i < DATA_TYPES.length; i++) {
            sql = str1 + PROCEDURE_BASE_NAME + i + " (IN param1 " + DATA_TYPES[i] + " ,OUT param2 " + DATA_TYPES[i]
                    + " )" + str2;

            try {
                jdbcStmt.execute(sql);
            } catch (Exception e) {
            }
        }
        jdbcStmt.close();
        jdbcConn.close();

    }

    static java.sql.Connection openJDBCConnection() throws Exception {
        Class.forName(getDriverClassName());
        java.sql.Connection jdbcConn = DriverManager.getConnection(getURL(), getUser(), getPassword());
        return jdbcConn;
    }

    static String getDriverClassName() {
        return "org.apache.derby.jdbc.EmbeddedDriver";
    }

    static String getURL() {
        String url = System.getProperty("DTETest.url");
        if (url != null)
            return url;
        else
            return "jdbc:derby:" + getDatabase() + ";create=true;user=" + getUser() + ";password=" + getPassword();
    }

    static String getUser() {
        String user = System.getProperty("DTETest.user");
        if (user != null)
            return user;
        else
            return "Actuate";
    }

    static String getPassword() {
        String pwd = System.getProperty("DTETest.password");
        if (pwd != null)
            return pwd;
        else
            return "Actuate";
    }

    static String getDatabase() {
        String database = System.getProperty("DTETest.database");
        if (database != null)
            return database;
        else
            return "DTETest";
    }
}

Related

  1. executeProcedure(Connection session, String sql)
  2. executeSqlScript(Connection conn, InputStream inputFile)
  3. executeSqlScript(Connection connection, URL scriptUrl)