Esempio n. 1
0
 /**
  * Backs up a database to a SQL script file.
  *
  * @param url the database URL
  * @param user the user name
  * @param password the password
  * @param fileName the script file
  */
 public static void execute(String url, String user, String password, String fileName)
     throws SQLException {
   OutputStream o = null;
   try {
     o = FileUtils.newOutputStream(fileName, false);
     execute(url, user, password, o);
   } finally {
     IOUtils.closeSilently(o);
   }
 }
Esempio n. 2
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);
   }
 }