62 lines
1.4 KiB
Java
62 lines
1.4 KiB
Java
package dev.alexzaw.fetchapi;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.ResultSetMetaData;
|
|
|
|
public class QueryResult implements AutoCloseable {
|
|
|
|
public final ResultSet resultSet;
|
|
public final String[] headers;
|
|
public final ResultSetMetaData metadata;
|
|
public final Connection connection;
|
|
public final PreparedStatement statement;
|
|
|
|
public QueryResult(
|
|
Connection conn,
|
|
PreparedStatement stmt,
|
|
ResultSet rs,
|
|
String[] headers,
|
|
ResultSetMetaData metadata
|
|
) {
|
|
this.connection = conn;
|
|
this.statement = stmt;
|
|
this.resultSet = rs;
|
|
this.headers = headers;
|
|
this.metadata = metadata;
|
|
}
|
|
|
|
public ResultSet getResultSet() {
|
|
return resultSet;
|
|
}
|
|
|
|
public String[] getHeaders() {
|
|
return headers;
|
|
}
|
|
|
|
public ResultSetMetaData getMetadata() {
|
|
return metadata;
|
|
}
|
|
|
|
public Connection getConnection() {
|
|
return connection;
|
|
}
|
|
|
|
public PreparedStatement getStatement() {
|
|
return statement;
|
|
}
|
|
|
|
@Override
|
|
public void close() throws Exception {
|
|
try {
|
|
if (resultSet != null) resultSet.close();
|
|
} finally {
|
|
try {
|
|
if (statement != null) statement.close();
|
|
} finally {
|
|
if (connection != null) connection.close();
|
|
}
|
|
}
|
|
}
|
|
} |