List of usage examples for org.springframework.jdbc.support JdbcUtils closeResultSet
public static void closeResultSet(@Nullable ResultSet rs)
From source file:io.kahu.hawaii.util.call.sql.response.UpdateIdResponseHandler.java
@Override public void addToResponse(PreparedStatement payload, Response<Long> response) throws ServerException { try {// ww w .ja v a 2 s . c o m ResultSet keys = payload.getGeneratedKeys(); if (keys != null) { try { keys.next(); Long keyValue = keys.getLong(1); response.set(keyValue); } finally { JdbcUtils.closeResultSet(keys); } } } catch (SQLException e) { response.setStatus(ResponseStatus.BACKEND_FAILURE, e); } }
From source file:net.mlw.vlh.adapter.jdbc.spring.util.SpringConnectionCreator.java
public void close(ResultSet result, PreparedStatement statement, Connection connection) { JdbcUtils.closeResultSet(result); JdbcUtils.closeStatement(statement); // deprecated since spring 1.2 DataSourceUtils.releaseConnection(connection, getDataSource()); }
From source file:net.paoding.rose.jade.provider.jdbctemplate.PreparedStatementCallbackReturnId.java
@Override public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { if (setter != null) { setter.setValues(ps);/*from w ww .j a v a 2 s . c o m*/ } ps.executeUpdate(); ResultSet keys = ps.getGeneratedKeys(); if (keys != null) { try { RowMapperResultSetExtractor extractor = new RowMapperResultSetExtractor( new SingleColumnRowMapper(Number.class), 1); return DataAccessUtils.requiredSingleResult((List<?>) extractor.extractData(keys)); } finally { JdbcUtils.closeResultSet(keys); } } return null; }
From source file:com.emc.ecs.sync.service.RowIterator.java
@Override public void close() { JdbcUtils.closeResultSet(rs); JdbcUtils.closeStatement(st); JdbcUtils.closeConnection(con); }
From source file:org.dcache.chimera.DirectoryStreamImpl.java
public void close() throws IOException { try {//w w w.j a v a 2s. c om JdbcUtils.closeResultSet(_resultSet); JdbcUtils.closeStatement(_statement); DataSourceUtils.releaseConnection(_connection, _jdbc.getDataSource()); } catch (DataAccessException e) { throw new IOException(e.getMessage(), e); } }
From source file:org.paxml.table.jdbc.JdbcTable.java
public void close(boolean closeConnection) { JdbcUtils.closeResultSet(rs); rs = null;/*from www . ja v a 2 s. c om*/ JdbcUtils.closeStatement(ps); ps = null; if (closeConnection) { JdbcUtils.closeConnection(con); } con = null; }
From source file:com.laxser.blitz.lama.provider.jdbc.PreparedStatementCallbackReturnId.java
@Override public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { if (setter != null) { setter.setValues(ps);//from ww w. j a v a2s . c o m } int updated = ps.executeUpdate(); if (updated == 0) { if (returnType.isArray()) { return Array.newInstance(wrappedIdType, 0); } else { return defaultValueOf(wrappedIdType); } } ResultSet keys = ps.getGeneratedKeys(); if (keys != null) { try { Object ret = null; if (returnType.isArray()) { keys.last(); int length = keys.getRow(); keys.beforeFirst(); ret = Array.newInstance(wrappedIdType, length); } for (int i = 0; keys.next(); i++) { Object value = mapper.mapRow(keys, i); if (value == null && idType.isPrimitive()) { // ?primitive??null?? value = defaultValueOf(wrappedIdType); } if (ret != null) { Array.set(ret, i + 1, value); } else { ret = value; break; } } return ret; } finally { JdbcUtils.closeResultSet(keys); } } else { if (returnType.isArray()) { return Array.newInstance(wrappedIdType, 0); } else { return defaultValueOf(wrappedIdType); } } }
From source file:com.thinkbiganalytics.server.KyloUpgradeDatabaseVersionChecker.java
/** * Query the Database for the Kylo Version * * @return the KyloVersion from the database, or null if not found or if an error occurs */// www . j a v a2 s .c om public KyloVersion getDatabaseVersion() { KyloVersion version = null; Connection connection = null; Statement statement = null; ResultSet resultSet = null; try { String user = environmentProperties.getPropertyValueAsString("spring.datasource.username"); String password = environmentProperties.getPropertyValueAsString("spring.datasource.password"); password = encryptionService.isEncrypted(password) ? encryptionService.decrypt(password) : password; String uri = environmentProperties.getPropertyValueAsString("spring.datasource.url"); String driverClassName = environmentProperties .getPropertyValueAsString("spring.datasource.driverClassName"); boolean testOnBorrow = BooleanUtils .toBoolean(environmentProperties.getPropertyValueAsString("spring.datasource.testOnBorrow")); String validationQuery = environmentProperties.getPropertyValueAsString("spring.data.validationQuery"); PoolingDataSourceService.DataSourceProperties dataSourceProperties = new PoolingDataSourceService.DataSourceProperties( user, password, uri, driverClassName, testOnBorrow, validationQuery); DataSource dataSource = PoolingDataSourceService.getDataSource(dataSourceProperties); connection = dataSource.getConnection(); String query = "SELECT MAJOR_VERSION,MINOR_VERSION FROM kylo.KYLO_VERSION "; statement = connection.createStatement(); ResultSet rs = statement.executeQuery(query); if (rs.next()) { String majorVersion = rs.getString("MAJOR_VERSION"); String minorVersion = rs.getString("MINOR_VERSION"); version = new KyloVersionUtil.Version(majorVersion, minorVersion); } } catch (SQLException e) { // this is ok.. If an error happens assume the upgrade is needed. The method will return a null value if errors occur and the upgrade app will start. } finally { JdbcUtils.closeStatement(statement); JdbcUtils.closeResultSet(resultSet); JdbcUtils.closeConnection(connection); } return version; }
From source file:com.thinkbiganalytics.server.upgrade.KyloUpgradeDatabaseVersionChecker.java
/** * Query the Database for the Kylo Version * * @return the KyloVersion from the database, or null if not found or if an error occurs *//*from w w w.ja va 2s . co m*/ public KyloVersion getDatabaseVersion() { KyloVersion version = null; Connection connection = null; Statement statement = null; ResultSet resultSet = null; try { String user = environmentProperties.getPropertyValueAsString("spring.datasource.username"); String password = environmentProperties.getPropertyValueAsString("spring.datasource.password"); password = encryptionService.isEncrypted(password) ? encryptionService.decrypt(password) : password; String uri = environmentProperties.getPropertyValueAsString("spring.datasource.url"); String driverClassName = environmentProperties .getPropertyValueAsString("spring.datasource.driverClassName"); boolean testOnBorrow = BooleanUtils .toBoolean(environmentProperties.getPropertyValueAsString("spring.datasource.testOnBorrow")); String validationQuery = environmentProperties .getPropertyValueAsString("spring.datasource.validationQuery"); PoolingDataSourceService.DataSourceProperties dataSourceProperties = new PoolingDataSourceService.DataSourceProperties( user, password, uri, driverClassName, testOnBorrow, validationQuery); DataSource dataSource = PoolingDataSourceService.getDataSource(dataSourceProperties); connection = dataSource.getConnection(); String query = "SELECT * FROM KYLO_VERSION ORDER BY MAJOR_VERSION DESC, MINOR_VERSION DESC, POINT_VERSION DESC, TAG DESC"; statement = connection.createStatement(); ResultSet rs = statement.executeQuery(query); if (rs.next()) { String majorVersion = rs.getString("MAJOR_VERSION"); String minorVersion = rs.getString("MINOR_VERSION"); String pointVersion = rs.getString("POINT_VERSION"); String tag = rs.getString("TAG"); version = new KyloVersionUtil.Version(majorVersion, minorVersion, pointVersion, tag); } } catch (SQLException e) { // this is ok.. If an error happens assume the upgrade is needed. The method will return a null value if errors occur and the upgrade app will start. e.printStackTrace(); } finally { JdbcUtils.closeStatement(statement); JdbcUtils.closeResultSet(resultSet); JdbcUtils.closeConnection(connection); } return version; }
From source file:me.j360.idgen.impl.SequenceIdGenServiceImpl.java
/** * Gets the next id as a Big Decimal. This method will only be called when * synchronized and when the data type is configured to be BigDecimal. * //w w w . j a v a 2 s. c om * @return the next id as a BigDecimal. * @throws IdCreationException */ protected BigDecimal getNextBigDecimalIdInner() { getLogger().debug("[IDGeneration Service] Requesting an Id using query: {}", query); try { // 2009.10.08 - without handling connection directly Connection conn = DataSourceUtils.getConnection(getDataSource()); PreparedStatement stmt = null; ResultSet rs = null; try { stmt = conn.prepareStatement(query); rs = stmt.executeQuery(); if (rs.next()) { return rs.getBigDecimal(1); } else { getLogger().error( "[IDGeneration Service] Unable to allocate a block of Ids. Query for Id did not return a value."); throw new IdCreationException( "[IDGeneration Service] Unable to allocate a block of Ids. Query for Id did not return a value."); } } finally { if (rs != null) { JdbcUtils.closeResultSet(rs); } if (stmt != null) { JdbcUtils.closeStatement(stmt); } // 2009.10.08 - without handling connection directly if (conn != null) { DataSourceUtils.releaseConnection(conn, getDataSource()); } } // 2009.10.08 - without handling connection directly } catch (Exception ex) { if (ex instanceof IdCreationException) throw (IdCreationException) ex; getLogger().error( "[IDGeneration Service] We can't get a connection. So, unable to allocate a block of Ids.", ex); throw new IdCreationException( "[IDGeneration Service] We can't get a connection. So, unable to allocate a block of Ids.", ex); } }