Java JDBC PostgreSQL Connection ClearDatabase()

Here you can find the source of ClearDatabase()

Description

Clear Database

License

Open Source License

Declaration

public static void ClearDatabase() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.sql.*;

public class Main {
    public static void ClearDatabase() {
        String ConnectionString;/*  w w  w.ja  v  a2 s .  c  om*/
        Connection PostgreSQLConnection;
        Statement stmt;

        ConnectionString = "jdbc:postgresql://127.0.0.1:5432/abia/";
        try {
            Class.forName("org.postgresql.Driver");
        } catch (Exception e) {
            System.out.println(e);
        }

        try {
            PostgreSQLConnection = DriverManager.getConnection(
                    ConnectionString, "abia", "");
            stmt = PostgreSQLConnection.createStatement();

            try {
                stmt.execute("drop table agentdata");
            } catch (Exception e) {
                System.out.println(e);
            }
            try {
                stmt.execute("drop table agents");
            } catch (Exception e) {
                System.out.println(e);
            }
            try {
                stmt.execute("drop table momentum");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table bollingerbands");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table portfolio");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table estadoportfolio");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table novoportfolio");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table novoestadoportfolio");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table papelemportfolio");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table novopapelemportfolio");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table estadopapelemportfolio");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table cotacao");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table cotacaoindice");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table empresa");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table indice");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table movingaverage");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table papel");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table papelemindice");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table pregao");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table rsi");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop sequence seq_agents");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop sequence seq_timestamp");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table stochasticoscillator");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table technicalanalisys");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table technicalsubanalisys");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table trend");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table balancete");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table prediction");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table contacontabil");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table composicaoindividamento");
            } catch (Exception e) {
                System.out.println(e);
            }

            try {
                stmt.execute("drop table fundamentalanalisys");
            } catch (Exception e) {
                System.out.println(e);
            }
            try {
                stmt.execute("drop table fundamentalsubanalisys");
            } catch (Exception e) {
                System.out.println(e);
            }
            try {
                stmt.execute("drop table girodoativo");
            } catch (Exception e) {
                System.out.println(e);
            }
            try {
                stmt.execute("drop table imobilizacaopatrimonioliquido");
            } catch (Exception e) {
                System.out.println(e);
            }
            try {
                stmt.execute("drop table liquidezcorrente");
            } catch (Exception e) {
                System.out.println(e);
            }
            try {
                stmt.execute("drop table liquidezgeral");
            } catch (Exception e) {
                System.out.println(e);
            }
            try {
                stmt.execute("drop table retornosobrevendas");
            } catch (Exception e) {
                System.out.println(e);
            }
            try {
                stmt.execute("drop table timestamp");
            } catch (Exception e) {
                System.out.println(e);
            }

        } catch (Exception e) {
            System.out.println(e);
        }

    }
}

Related

  1. createConnection()
  2. getConnection()
  3. getConnection()
  4. getDataFromTable(String tableName, String[] columns)