Удаление строки таблицы и поздание новой со значениями по умолчанию (Statement)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Удалит все
String removeRow = "delete from MY_TABLE";  

// Таблица заполняется значениями по умолчанию.
String insertRow = "insert into MY_TABLE (id) values (1)";


private void runSetup(String removeRow, String insertRow){

    Statement stmt = null;

    try {
        stmt = DBUtils.getDBTransaction().createStatement(1);
        stmt.executeUpdate(removeRow);
        stmt.executeUpdate(insertRow);
        ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl").getTransaction().commit();
        }
    catch (SQLException ex ){
        ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl").getTransaction().rollback();
        System.out.println("EXCEPTION " + ex.toString());
    }

    finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {

            }
        }
    }
}