Java JDBC PostgreSQL Connection resetTestDB()

Here you can find the source of resetTestDB()

Description

reset Test DB

License

MIT License

Declaration

protected static void resetTestDB() 

Method Source Code

//package com.java2s;
/*// w w  w  .j ava  2  s.  c  o m
 * Wegas
 * http://wegas.albasim.ch
 *
 * Copyright (c) 2013 School of Business and Engineering Vaud, Comem
 * Licensed under the MIT License
 */

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    private static Connection connection = null;

    protected static void resetTestDB() {
        if (connection == null) {
            try {
                connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/wegas_test", "user",
                        "1234");
                try (Statement st = connection.createStatement()) {
                    st.execute("DROP SCHEMA public CASCADE;");
                    st.execute("CREATE SCHEMA public;");
                }
                connection.commit();
            } catch (SQLException ex) {
                System.out.println("Error creating database");
            }
        }
    }
}

Related

  1. getListDatabaseFromMaster()
  2. getPostgresConnection()
  3. getPostgresConnection()
  4. getPostgresJDBCConnection(String host, int port, String nameDB, String userDB, String passwordDB)
  5. getPostgresSQLConnection(String hostname, int portNumber, String databaseName, String dbuser, String dbpasswort)