1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| String backupScript = "..." ;
Session session = HibernateSessionFactory.getSession();
InputStream ips = new FileInputStream(backupScript);
BufferedInputStream bis= new BufferedInputStream(ips);
InputStreamReader ipsr = new InputStreamReader(bis);
BufferedReader br = new BufferedReader(ipsr);
String ligne;
String sqlQuery = "";
while ((ligne=br.readLine()) != null) {
if (ligne.startsWith("--")) {
continue;
}
sqlQuery += ligne;
if (ligne.endsWith(";")) {
Transaction transaction = session.beginTransaction();
session.createSQLQuery(sqlQuery) .executeUpdate();
transaction.commit();
sqlQuery = "";
}
}
br.close();
session.close(); |