public static Long insertLabel(Long parent_id, String name) throws SQLException { try { // System.out.println("Insert: " + name + ", " + parent_id); PreparedStatement insertLabelStmt = SqlHelper.getInsertLabelStmt(); insertLabelStmt.setString(1, name); if (parent_id != null) insertLabelStmt.setLong(2, parent_id); else insertLabelStmt.setNull(2, java.sql.Types.BIGINT); insertLabelStmt.executeUpdate(); ResultSet keys = insertLabelStmt.getGeneratedKeys(); keys.next(); return keys.getLong(1); } catch (MySQLIntegrityConstraintViolationException e) { // ignore, this is just a duplicate tweet entry, that's rather normal } return null; }