List of usage examples for java.sql PreparedStatement setNull
void setNull(int parameterIndex, int sqlType) throws SQLException;
NULL
. From source file:org.apache.ddlutils.platform.PlatformImplBase.java
/** * This is the core method to set the parameter of a prepared statement to a given value. * The primary purpose of this method is to call the appropriate method on the statement, * and to give database-specific implementations the ability to change this behavior. * //www .jav a 2 s. co m * @param statement The statement * @param sqlIndex The parameter index * @param typeCode The JDBC type code * @param value The value * @throws SQLException If an error occurred while setting the parameter value */ protected void setStatementParameterValue(PreparedStatement statement, int sqlIndex, int typeCode, Object value) throws SQLException { if (value == null) { statement.setNull(sqlIndex, typeCode); } else if (value instanceof String) { statement.setString(sqlIndex, (String) value); } else if (value instanceof byte[]) { statement.setBytes(sqlIndex, (byte[]) value); } else if (value instanceof Boolean) { statement.setBoolean(sqlIndex, ((Boolean) value).booleanValue()); } else if (value instanceof Byte) { statement.setByte(sqlIndex, ((Byte) value).byteValue()); } else if (value instanceof Short) { statement.setShort(sqlIndex, ((Short) value).shortValue()); } else if (value instanceof Integer) { statement.setInt(sqlIndex, ((Integer) value).intValue()); } else if (value instanceof Long) { statement.setLong(sqlIndex, ((Long) value).longValue()); } else if (value instanceof BigDecimal) { // setObject assumes a scale of 0, so we rather use the typed setter statement.setBigDecimal(sqlIndex, (BigDecimal) value); } else if (value instanceof Float) { statement.setFloat(sqlIndex, ((Float) value).floatValue()); } else if (value instanceof Double) { statement.setDouble(sqlIndex, ((Double) value).doubleValue()); } else { statement.setObject(sqlIndex, value, typeCode); } }
From source file:axiom.objectmodel.db.NodeManager.java
private void setStatementValues(PreparedStatement stmt, int stmtNumber, Property p, int columnType) throws SQLException { if (p.getValue() == null) { stmt.setNull(stmtNumber, columnType); } else {/*from w w w . j a v a 2s . c o m*/ switch (columnType) { case Types.BIT: case Types.TINYINT: case Types.BIGINT: case Types.SMALLINT: case Types.INTEGER: stmt.setLong(stmtNumber, p.getIntegerValue()); break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: case Types.NUMERIC: case Types.DECIMAL: stmt.setDouble(stmtNumber, p.getFloatValue()); break; case Types.VARBINARY: case Types.BINARY: case Types.BLOB: stmt.setString(stmtNumber, p.getStringValue()); break; case Types.LONGVARBINARY: case Types.LONGVARCHAR: try { stmt.setString(stmtNumber, p.getStringValue()); } catch (SQLException x) { String str = p.getStringValue(); Reader r = new StringReader(str); stmt.setCharacterStream(stmtNumber, r, str.length()); } break; case Types.CLOB: String val = p.getStringValue(); Reader isr = new StringReader(val); stmt.setCharacterStream(stmtNumber, isr, val.length()); break; case Types.CHAR: case Types.VARCHAR: case Types.OTHER: stmt.setString(stmtNumber, p.getStringValue()); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: stmt.setTimestamp(stmtNumber, p.getTimestampValue()); break; case Types.NULL: stmt.setNull(stmtNumber, 0); break; default: stmt.setString(stmtNumber, p.getStringValue()); break; } } }
From source file:org.apache.phoenix.end2end.DateTimeIT.java
private String initAtable() throws SQLException { String tableName = generateUniqueName(); ensureTableCreated(getUrl(), tableName, ATABLE_NAME, (byte[][]) null, null); PreparedStatement stmt = conn.prepareStatement("upsert into " + tableName + "(" + " ORGANIZATION_ID, " + " ENTITY_ID, " + " A_STRING, " + " B_STRING, " + " A_INTEGER, " + " A_DATE, " + " X_DECIMAL, " + " X_LONG, " + " X_INTEGER," + " Y_INTEGER," + " A_BYTE," + " A_SHORT," + " A_FLOAT," + " A_DOUBLE," + " A_UNSIGNED_FLOAT," + " A_UNSIGNED_DOUBLE)" + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, tenantId);/*from ww w .j av a 2s. c o m*/ stmt.setString(2, ROW1); stmt.setString(3, A_VALUE); stmt.setString(4, B_VALUE); stmt.setInt(5, 1); stmt.setDate(6, date); stmt.setBigDecimal(7, null); stmt.setNull(8, Types.BIGINT); stmt.setNull(9, Types.INTEGER); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 1); stmt.setShort(12, (short) 128); stmt.setFloat(13, 0.01f); stmt.setDouble(14, 0.0001); stmt.setFloat(15, 0.01f); stmt.setDouble(16, 0.0001); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW2); stmt.setString(3, A_VALUE); stmt.setString(4, C_VALUE); stmt.setInt(5, 2); stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1)); stmt.setBigDecimal(7, null); stmt.setNull(8, Types.BIGINT); stmt.setNull(9, Types.INTEGER); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 2); stmt.setShort(12, (short) 129); stmt.setFloat(13, 0.02f); stmt.setDouble(14, 0.0002); stmt.setFloat(15, 0.02f); stmt.setDouble(16, 0.0002); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW3); stmt.setString(3, A_VALUE); stmt.setString(4, E_VALUE); stmt.setInt(5, 3); stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2)); stmt.setBigDecimal(7, null); stmt.setNull(8, Types.BIGINT); stmt.setNull(9, Types.INTEGER); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 3); stmt.setShort(12, (short) 130); stmt.setFloat(13, 0.03f); stmt.setDouble(14, 0.0003); stmt.setFloat(15, 0.03f); stmt.setDouble(16, 0.0003); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW4); stmt.setString(3, A_VALUE); stmt.setString(4, B_VALUE); stmt.setInt(5, 4); stmt.setDate(6, date == null ? null : date); stmt.setBigDecimal(7, null); stmt.setNull(8, Types.BIGINT); stmt.setNull(9, Types.INTEGER); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 4); stmt.setShort(12, (short) 131); stmt.setFloat(13, 0.04f); stmt.setDouble(14, 0.0004); stmt.setFloat(15, 0.04f); stmt.setDouble(16, 0.0004); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW5); stmt.setString(3, B_VALUE); stmt.setString(4, C_VALUE); stmt.setInt(5, 5); stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1)); stmt.setBigDecimal(7, null); stmt.setNull(8, Types.BIGINT); stmt.setNull(9, Types.INTEGER); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 5); stmt.setShort(12, (short) 132); stmt.setFloat(13, 0.05f); stmt.setDouble(14, 0.0005); stmt.setFloat(15, 0.05f); stmt.setDouble(16, 0.0005); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW6); stmt.setString(3, B_VALUE); stmt.setString(4, E_VALUE); stmt.setInt(5, 6); stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2)); stmt.setBigDecimal(7, null); stmt.setNull(8, Types.BIGINT); stmt.setNull(9, Types.INTEGER); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 6); stmt.setShort(12, (short) 133); stmt.setFloat(13, 0.06f); stmt.setDouble(14, 0.0006); stmt.setFloat(15, 0.06f); stmt.setDouble(16, 0.0006); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW7); stmt.setString(3, B_VALUE); stmt.setString(4, B_VALUE); stmt.setInt(5, 7); stmt.setDate(6, date == null ? null : date); stmt.setBigDecimal(7, BigDecimal.valueOf(0.1)); stmt.setLong(8, 5L); stmt.setInt(9, 5); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 7); stmt.setShort(12, (short) 134); stmt.setFloat(13, 0.07f); stmt.setDouble(14, 0.0007); stmt.setFloat(15, 0.07f); stmt.setDouble(16, 0.0007); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW8); stmt.setString(3, B_VALUE); stmt.setString(4, C_VALUE); stmt.setInt(5, 8); stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1)); stmt.setBigDecimal(7, BigDecimal.valueOf(3.9)); long l = Integer.MIN_VALUE - 1L; assert (l < Integer.MIN_VALUE); stmt.setLong(8, l); stmt.setInt(9, 4); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 8); stmt.setShort(12, (short) 135); stmt.setFloat(13, 0.08f); stmt.setDouble(14, 0.0008); stmt.setFloat(15, 0.08f); stmt.setDouble(16, 0.0008); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW9); stmt.setString(3, C_VALUE); stmt.setString(4, E_VALUE); stmt.setInt(5, 9); stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2)); stmt.setBigDecimal(7, BigDecimal.valueOf(3.3)); l = Integer.MAX_VALUE + 1L; assert (l > Integer.MAX_VALUE); stmt.setLong(8, l); stmt.setInt(9, 3); stmt.setInt(10, 300); stmt.setByte(11, (byte) 9); stmt.setShort(12, (short) 0); stmt.setFloat(13, 0.09f); stmt.setDouble(14, 0.0009); stmt.setFloat(15, 0.09f); stmt.setDouble(16, 0.0009); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW10); stmt.setString(3, B_VALUE); stmt.setString(4, B_VALUE); stmt.setInt(5, 7); // Intentionally null stmt.setDate(6, null); stmt.setBigDecimal(7, BigDecimal.valueOf(0.1)); stmt.setLong(8, 5L); stmt.setInt(9, 5); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 7); stmt.setShort(12, (short) 134); stmt.setFloat(13, 0.07f); stmt.setDouble(14, 0.0007); stmt.setFloat(15, 0.07f); stmt.setDouble(16, 0.0007); stmt.execute(); conn.commit(); return tableName; }
From source file:com.flexive.core.storage.genericSQL.GenericHierarchicalStorage.java
/** * Set a prepared statements values to <code>NULL</code> from startPos to endPos * * @param ps prepared statement/* w w w. j a va 2 s .c o m*/ * @param startPos start position * @param endPos end position * @throws SQLException on errors */ protected static void clearPreparedStatement(PreparedStatement ps, int startPos, int endPos) throws SQLException { for (int i = startPos; i <= endPos; i++) ps.setNull(i, Types.NULL); }
From source file:dk.netarkivet.harvester.datamodel.DomainDBDAO.java
/** * Update the list of harvest info for the given domain, keeping IDs where * applicable.//from w ww .ja va 2 s . c o m * @param c * A connection to the database * @param d * A domain to update. * @throws SQLException * If any database problems occur during the update process. */ private void updateHarvestInfo(Connection c, Domain d) throws SQLException { List<Long> oldIDs = DBUtils.selectLongList(c, "SELECT historyinfo.historyinfo_id " + "FROM historyinfo, configurations " + "WHERE historyinfo.config_id " + "= configurations.config_id" + " AND configurations.domain_id = ?", d.getID()); PreparedStatement s = c.prepareStatement("UPDATE historyinfo SET " + "stopreason = ?, " + "objectcount = ?, " + "bytecount = ?, " + "config_id = " + " (SELECT config_id FROM configurations, domains" + " WHERE domains.domain_id = ?" + " AND configurations.name = ?" + " AND configurations.domain_id = domains.domain_id), " + "harvest_id = ?, " + "job_id = ? " + "WHERE historyinfo_id = ?"); Iterator<HarvestInfo> his = d.getHistory().getHarvestInfo(); while (his.hasNext()) { HarvestInfo hi = his.next(); if (hi.hasID() && oldIDs.remove(hi.getID())) { s.setInt(1, hi.getStopReason().ordinal()); s.setLong(2, hi.getCountObjectRetrieved()); s.setLong(3, hi.getSizeDataRetrieved()); s.setLong(4, d.getID()); s.setString(5, d.getConfiguration(hi.getDomainConfigurationName()).getName()); s.setLong(6, hi.getHarvestID()); if (hi.getJobID() != null) { s.setLong(7, hi.getJobID()); } else { s.setNull(7, Types.BIGINT); } s.setLong(8, hi.getID()); s.executeUpdate(); s.clearParameters(); } else { insertHarvestInfo(c, d, hi); } } if (oldIDs.size() != 0) { String message = "Not allowed to delete historyinfo " + oldIDs + " on " + d; log.debug(message); throw new IOFailure(message); } }
From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void update(final OpenbareRuimte openbareRuimte) throws DAOException { try {//from w w w. j av a2s . co m jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("update bag_openbare_ruimte set" + " aanduiding_record_inactief = ?," + " openbare_ruimte_naam = ?," + " officieel = ?," + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?," + " openbare_ruimte_type = ?," + " bron_documentdatum = ?," + " bron_documentnummer = ?," + " openbareruimte_status = ?," + " bag_woonplaats_id = ?," + " verkorte_openbare_ruimte_naam = ?" + " where bag_openbare_ruimte_id = ?" + " and aanduiding_record_correctie = ?" + " and begindatum_tijdvak_geldigheid = ?"); ps.setInt(1, openbareRuimte.getAanduidingRecordInactief().ordinal()); ps.setString(2, openbareRuimte.getOpenbareRuimteNaam()); ps.setInt(3, openbareRuimte.getOfficieel().ordinal()); if (openbareRuimte.getEinddatumTijdvakGeldigheid() == null) ps.setNull(4, Types.TIMESTAMP); else ps.setTimestamp(4, new Timestamp(openbareRuimte.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(5, openbareRuimte.getInOnderzoek().ordinal()); ps.setInt(6, openbareRuimte.getOpenbareRuimteType().ordinal()); ps.setDate(7, new Date(openbareRuimte.getDocumentdatum().getTime())); ps.setString(8, openbareRuimte.getDocumentnummer()); ps.setInt(9, openbareRuimte.getOpenbareruimteStatus().ordinal()); ps.setLong(10, openbareRuimte.getGerelateerdeWoonplaats()); ps.setString(11, openbareRuimte.getVerkorteOpenbareRuimteNaam()); ps.setLong(12, openbareRuimte.getIdentificatie()); ps.setLong(13, openbareRuimte.getAanduidingRecordCorrectie()); ps.setTimestamp(14, new Timestamp(openbareRuimte.getBegindatumTijdvakGeldigheid().getTime())); return ps; } }); } catch (DataAccessException e) { throw new DAOException("Error updating openbare ruimte: " + openbareRuimte.getIdentificatie(), e); } }
From source file:org.openanzo.datasource.nodecentric.sql.GlitterRdbWrapper.java
/** * Runs the countValidRevisionedGraphsInSet prepared statement. * <code>/*w w w . ja va2s .c o m*/ * SELECT COUNT(1) FROM GLITTERUNIT WHERE EXISTS( SELECT NG.ID FROM QUERY_GRAPHS,NAMEDGRAPHS NG WHERE QUERY_GRAPHS.DSID=? AND (NG.ID =QUERY_GRAPHS.ID OR NG.METAID=QUERY_GRAPHS.ID) AND ((NG.HEND IS NULL AND NG.COMMITTED=0) OR(NG.HEND IS NOT NULL AND NG.COMMITTED <0)) ) * </code> * *@param stmtProvider * factory and cache of PreparedStatments *@param connection * connection to underlying database * *@param dsId template parameter * *@return long *@throws org.openanzo.jdbc.utils.RdbException */ public static long countValidRevisionedGraphsInSet( final org.openanzo.jdbc.utils.PreparedStatementProvider stmtProvider, final java.sql.Connection connection, Long dsId) throws org.openanzo.jdbc.utils.RdbException { java.sql.PreparedStatement ps = null; //long startTimer=System.currentTimeMillis(); try { ps = stmtProvider.getPreparedSQLStatement(countValidRevisionedGraphsInSet, new String[] {}, connection); int argc = 1; if (dsId == null) { ps.setNull(argc++, java.sql.Types.BIGINT); } else { ps.setLong(argc++, dsId); } java.sql.ResultSet rs = null; try { try { rs = ps.executeQuery(); } catch (java.sql.SQLException sqle) { if (sqle.getErrorCode() == 1205) { int retries = 0; while (retries < 5) { try { Thread.sleep(5000); } catch (InterruptedException ie) { throw sqle; } try { rs = ps.executeQuery(); break; } catch (java.sql.SQLException sqleInner) { if (sqleInner.getErrorCode() == 1205) { retries++; } else { throw sqleInner; } } } if (retries >= 5) { throw sqle; } } else { throw sqle; } } if (!rs.next()) return 0; long val = rs.getLong(1); return val; } finally { if (rs != null) { try { rs.close(); } catch (java.sql.SQLException sqle) { if (log.isDebugEnabled()) log.debug(org.openanzo.exceptions.LogUtils.RDB_MARKER, "Error closing result set", sqle); } } } } catch (java.sql.SQLException e) { throw new org.openanzo.jdbc.utils.RdbException( org.openanzo.exceptions.ExceptionConstants.RDB.FAILED_EXECUTING_SQL, e, "countValidRevisionedGraphsInSet", stmtProvider.getSqlString(countValidRevisionedGraphsInSet), "" + "dsId=" + ((dsId != null) ? dsId.toString() : "null"), ""); } finally { if (ps != null) { try { ps.close(); } catch (java.sql.SQLException sqle) { if (log.isDebugEnabled()) log.debug(org.openanzo.exceptions.LogUtils.RDB_MARKER, "Error closing prepared statement", sqle); } } //long endtimer=(System.currentTimeMillis()-startTimer); //if(endtimer>CUTOFF)System.out.println("[countValidRevisionedGraphsInSet]"+endtimer); } }
From source file:org.openanzo.datasource.nodecentric.sql.Backup.java
/** * Runs the restoreStatement prepared statement. * <code>/*from w ww . j a va 2s .com*/ * INSERT INTO STATEMENTS(ID,METADATA,UUID,NAMEDGRAPHID, SUBJECT, PREDICATE, OBJECT,RSTART,REND,COMMITTED) VALUES (?,?,?,?,?,?,?,?,?,0); * </code> * *@param stmtProvider * factory and cache of PreparedStatments *@param connection * connection to underlying database * *@param id template parameter *@param metadata template parameter *@param uuid template parameter *@param namedGraphId template parameter *@param subject template parameter *@param predicate template parameter *@param object template parameter *@param rstart template parameter *@param rend template parameter * *@return int *@throws org.openanzo.jdbc.utils.RdbException */ public static int restoreStatement(final org.openanzo.jdbc.utils.PreparedStatementProvider stmtProvider, final java.sql.Connection connection, String id, int metadata, long uuid, long namedGraphId, long subject, long predicate, long object, long rstart, Long rend) throws org.openanzo.jdbc.utils.RdbException { java.sql.PreparedStatement ps = null; //long startTimer=System.currentTimeMillis(); try { ps = stmtProvider.getPreparedSQLStatement(restoreStatement, new String[] {}, connection); int argc = 1; if (id == null) { throw new org.openanzo.jdbc.utils.RdbException( org.openanzo.exceptions.ExceptionConstants.RDB.NULL_PARAMETER, "id", "restoreStatement"); } else { ps.setString(argc++, id); } ps.setInt(argc++, metadata); ps.setLong(argc++, uuid); ps.setLong(argc++, namedGraphId); ps.setLong(argc++, subject); ps.setLong(argc++, predicate); ps.setLong(argc++, object); ps.setLong(argc++, rstart); if (rend == null) { ps.setNull(argc++, java.sql.Types.BIGINT); } else { ps.setLong(argc++, rend); } int counter = 0; try { counter = ps.executeUpdate(); } catch (java.sql.SQLException sqle) { if (sqle.getErrorCode() == 1205) { int retries = 0; while (retries < 5) { try { Thread.sleep(5000); } catch (InterruptedException ie) { throw sqle; } try { counter = ps.executeUpdate(); break; } catch (java.sql.SQLException sqleInner) { if (sqleInner.getErrorCode() == 1205) { retries++; } else { throw sqleInner; } } } if (retries >= 5) { throw sqle; } } else { throw sqle; } } return counter; } catch (java.sql.SQLException e) { throw new org.openanzo.jdbc.utils.RdbException( org.openanzo.exceptions.ExceptionConstants.RDB.FAILED_EXECUTING_SQL, e, "restoreStatement", stmtProvider.getSqlString(restoreStatement), "" + "id=" + ((id != null) ? id.toString() : "null") + "," + "metadata=" + (metadata) + "," + "uuid=" + (uuid) + "," + "namedGraphId=" + (namedGraphId) + "," + "subject=" + (subject) + "," + "predicate=" + (predicate) + "," + "object=" + (object) + "," + "rstart=" + (rstart) + "," + "rend=" + ((rend != null) ? rend.toString() : "null"), ""); } finally { if (ps != null) { try { ps.close(); } catch (java.sql.SQLException sqle) { if (log.isDebugEnabled()) log.debug(org.openanzo.exceptions.LogUtils.RDB_MARKER, "Error closing prepared statement", sqle); } } //long endtimer=(System.currentTimeMillis()-startTimer); //if(endtimer>CUTOFF)System.out.println("[restoreStatement]"+endtimer); } }
From source file:org.openanzo.datasource.nodecentric.sql.GlitterRdbWrapper.java
/** * Runs the countValidNonRevisionedGraphsInSet prepared statement. * <code>/* ww w. j a v a 2 s . co m*/ * SELECT COUNT(1) FROM GLITTERUNIT WHERE EXISTS( SELECT NG.ID FROM QUERY_GRAPHS,NAMEDGRAPHS_NR NG WHERE QUERY_GRAPHS.DSID=? AND (NG.ID =QUERY_GRAPHS.ID OR NG.METAID=QUERY_GRAPHS.ID) AND NG.COMMITTED <=0 ) * </code> * *@param stmtProvider * factory and cache of PreparedStatments *@param connection * connection to underlying database * *@param dsId template parameter * *@return long *@throws org.openanzo.jdbc.utils.RdbException */ public static long countValidNonRevisionedGraphsInSet( final org.openanzo.jdbc.utils.PreparedStatementProvider stmtProvider, final java.sql.Connection connection, Long dsId) throws org.openanzo.jdbc.utils.RdbException { java.sql.PreparedStatement ps = null; //long startTimer=System.currentTimeMillis(); try { ps = stmtProvider.getPreparedSQLStatement(countValidNonRevisionedGraphsInSet, new String[] {}, connection); int argc = 1; if (dsId == null) { ps.setNull(argc++, java.sql.Types.BIGINT); } else { ps.setLong(argc++, dsId); } java.sql.ResultSet rs = null; try { try { rs = ps.executeQuery(); } catch (java.sql.SQLException sqle) { if (sqle.getErrorCode() == 1205) { int retries = 0; while (retries < 5) { try { Thread.sleep(5000); } catch (InterruptedException ie) { throw sqle; } try { rs = ps.executeQuery(); break; } catch (java.sql.SQLException sqleInner) { if (sqleInner.getErrorCode() == 1205) { retries++; } else { throw sqleInner; } } } if (retries >= 5) { throw sqle; } } else { throw sqle; } } if (!rs.next()) return 0; long val = rs.getLong(1); return val; } finally { if (rs != null) { try { rs.close(); } catch (java.sql.SQLException sqle) { if (log.isDebugEnabled()) log.debug(org.openanzo.exceptions.LogUtils.RDB_MARKER, "Error closing result set", sqle); } } } } catch (java.sql.SQLException e) { throw new org.openanzo.jdbc.utils.RdbException( org.openanzo.exceptions.ExceptionConstants.RDB.FAILED_EXECUTING_SQL, e, "countValidNonRevisionedGraphsInSet", stmtProvider.getSqlString(countValidNonRevisionedGraphsInSet), "" + "dsId=" + ((dsId != null) ? dsId.toString() : "null"), ""); } finally { if (ps != null) { try { ps.close(); } catch (java.sql.SQLException sqle) { if (log.isDebugEnabled()) log.debug(org.openanzo.exceptions.LogUtils.RDB_MARKER, "Error closing prepared statement", sqle); } } //long endtimer=(System.currentTimeMillis()-startTimer); //if(endtimer>CUTOFF)System.out.println("[countValidNonRevisionedGraphsInSet]"+endtimer); } }
From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void update(final Pand origineel, final Pand mutation) throws DAOException { try {/*from w ww . j a v a 2 s . co m*/ jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("update bag_pand set" + " aanduiding_record_inactief = ?," + " aanduiding_record_correctie = ?," + " officieel = ?," + " pand_geometrie = ?," + " bouwjaar = ?," + " pand_status = ?," + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?," + " bron_documentdatum = ?," + " bron_documentnummer = ?" + " where bag_pand_id = ?" + " and aanduiding_record_correctie = ?" + " and begindatum_tijdvak_geldigheid = ?"); ps.setInt(1, mutation.getAanduidingRecordInactief().ordinal()); ps.setLong(2, mutation.getAanduidingRecordCorrectie()); ps.setInt(3, mutation.getOfficieel().ordinal()); ps.setString(4, mutation.getPandGeometrie()); ps.setInt(5, mutation.getBouwjaar()); ps.setString(6, mutation.getPandStatus()); if (mutation.getEinddatumTijdvakGeldigheid() == null) ps.setNull(7, Types.TIMESTAMP); else ps.setTimestamp(7, new Timestamp(mutation.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(8, mutation.getInOnderzoek().ordinal()); ps.setDate(9, new Date(mutation.getDocumentdatum().getTime())); ps.setString(10, mutation.getDocumentnummer()); ps.setLong(11, origineel.getIdentificatie()); ps.setLong(12, origineel.getAanduidingRecordCorrectie()); ps.setTimestamp(13, new Timestamp(origineel.getBegindatumTijdvakGeldigheid().getTime())); return ps; } }); } catch (DataAccessException e) { throw new DAOException("Error updating pand: " + origineel.getIdentificatie(), e); } }