Beispiel #1
0
 private static void processScript(
     String url, String user, String password, String fileName, String options1, String options2)
     throws SQLException {
   Connection conn = null;
   Statement stat = null;
   try {
     com.codefollower.h2.Driver.load();
     conn = DriverManager.getConnection(url, user, password);
     stat = conn.createStatement();
     String sql = "SCRIPT " + options1 + " TO '" + fileName + "' " + options2;
     stat.execute(sql);
   } finally {
     JdbcUtils.closeSilently(stat);
     JdbcUtils.closeSilently(conn);
   }
 }
Beispiel #2
0
 /**
  * Backs up a database to a stream. The stream is not closed.
  *
  * @param url the database URL
  * @param user the user name
  * @param password the password
  * @param out the output stream
  */
 public static void execute(String url, String user, String password, OutputStream out)
     throws SQLException {
   Connection conn = null;
   try {
     com.codefollower.h2.Driver.load();
     conn = DriverManager.getConnection(url, user, password);
     process(conn, out);
   } finally {
     JdbcUtils.closeSilently(conn);
   }
 }
Beispiel #3
0
 /**
  * Backs up a database to a stream. The stream is not closed. The connection is not closed.
  *
  * @param conn the connection
  * @param out the output stream
  */
 static void process(Connection conn, OutputStream out) throws SQLException {
   Statement stat = null;
   try {
     stat = conn.createStatement();
     PrintWriter writer = new PrintWriter(IOUtils.getBufferedWriter(out));
     ResultSet rs = stat.executeQuery("SCRIPT");
     while (rs.next()) {
       String s = rs.getString(1);
       writer.println(s);
     }
     writer.flush();
   } finally {
     JdbcUtils.closeSilently(stat);
   }
 }