Java JDBC Derby Connection removeUnitDB()

Here you can find the source of removeUnitDB()

Description

remove Unit DB

License

Apache License

Declaration

public static void removeUnitDB() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class Main {
    public static void removeUnitDB() {
        try {/*from   w w  w  .  ja  va  2  s.co m*/
            // shut down embedded database connection if there is one.
            DriverManager.getConnection("jdbc:derby:memory:flexims;drop=true", "flexims", "123456");
        } catch (SQLException e) {
            // ignore
        }
        //      // // avoid table created from other test
        //      // FileUtils.deleteQuietly(new File("target/flexims"));
        //      if (new File("target/flexims").exists()) {
        //         throw new RuntimeException("database exists. It can not be deleted");
        //      }
    }

    public static Connection getConnection() throws SQLException {
        return getDerbyUnitConnection();
    }

    public static Connection getDerbyUnitConnection() throws SQLException {
        String url = "jdbc:derby:memory:flexims;create=true";
        Properties props = new Properties();
        props.setProperty("user", "flexims");
        props.setProperty("password", "123456");
        return DriverManager.getConnection(url, props);

    }
}

Related

  1. getRowsFromDatabase(Connection con, int numberOfRows, boolean reuseConnection, String driver, String dsn, String user, String password, String tableName, String whereString, String orderByString, String groupByString)
  2. getSessionIds()
  3. getSize2()
  4. getTables(File database)
  5. printStats(String statstring)
  6. saveContact(String fName, String lName)
  7. startDerby()
  8. startDerbyInEmbeddedMode()
  9. stopDerby()