
net.dongliu.dbutils.SQLResultSet Maven / Gradle / Ivy
package net.dongliu.dbutils;
import net.dongliu.dbutils.exception.UncheckedSQLException;
import net.dongliu.dbutils.handlers.*;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;
/**
* Class for result set retrieve.
*
* @author Liu Dong
*/
public class SQLResultSet implements AutoCloseable {
private final ResultSet resultSet;
private final AutoCloseable[] closeables;
public SQLResultSet(ResultSet resultSet, AutoCloseable... closeables) {
this.resultSet = Objects.requireNonNull(resultSet);
this.closeables = Objects.requireNonNull(closeables);
}
/**
* Handler result, and return converted values
*/
@SuppressWarnings("unchecked")
public T handle(ResultSetHandler handler) {
try {
return handler.handle(resultSet);
} catch (SQLException e) {
throw new UncheckedSQLException(e);
} finally {
close();
}
}
/**
* Return query result as List of raw object array
*/
@Nonnull
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy