Java JDBC Derby Connection deleteTestData()

Here you can find the source of deleteTestData()

Description

delete Test Data

License

Open Source License

Declaration

static void deleteTestData() 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://  w  w  w.  j  av  a 2  s  . c  o m
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

import java.sql.DriverManager;

public class Main {
    /** Test table name */
    final static String TABLE_NAME = "\"test_oda_jdbc\"";

    static void deleteTestData() throws Exception {
        java.sql.Connection jdbcConn = openJDBCConnection();
        java.sql.Statement jdbcStmt = jdbcConn.createStatement();
        String sql = "drop table " + TABLE_NAME;
        jdbcStmt.execute(sql);
        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. closeDB()
  2. createAndOpen(String databaseName)
  3. createConnection()
  4. createConnection(String userName, String password)
  5. createXATransactionView(Statement s)
  6. existsInSessionTable(String id, boolean verbose)
  7. getConnection()
  8. getConnection()
  9. getDatabaseConnection()