Exemplo n.º 1
0
  private synchronized void init() throws SQLException {
    if (isClosed) return;

    // do tables exists?
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(TABLE_NAMES_SELECT_STMT);

    ArrayList<String> missingTables = new ArrayList(TABLES.keySet());
    while (rs.next()) {
      String tableName = rs.getString("name");
      missingTables.remove(tableName);
    }

    for (String missingTable : missingTables) {
      try {
        Statement createStmt = conn.createStatement();
        // System.out.println("Adding table "+ missingTable);
        createStmt.executeUpdate(TABLES.get(missingTable));
        createStmt.close();

      } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
      }
    }
  }
Exemplo n.º 2
0
 public boolean delete(String table, String deleteString) {
   Statement stmt = null;
   try {
     stmt = conn.createStatement();
     stmt.executeUpdate("delete from " + table + " where " + deleteString + ";");
     return true;
   } catch (SQLException sqe) {
     sqe.printStackTrace();
     return false;
   } finally {
     if (stmt != null)
       try {
         stmt.close();
       } catch (SQLException sqe2) {
         sqe2.printStackTrace();
       }
   }
 }
Exemplo n.º 3
0
 public boolean delete() {
   Statement stmt = null;
   try {
     stmt = conn.createStatement();
     stmt.executeUpdate(deleteStatement());
     return true;
   } catch (SQLException sqe) {
     System.err.println(deleteStatement());
     sqe.printStackTrace();
     return false;
   } finally {
     if (stmt != null)
       try {
         stmt.close();
       } catch (SQLException sqe2) {
         sqe2.printStackTrace();
       }
   }
 }