import java.sql.SQLException;
import java.sql.Timestamp;
-public class GigiPreparedStatement {
+public class GigiPreparedStatement implements AutoCloseable {
private PreparedStatement target;
- public GigiPreparedStatement(PreparedStatement preparedStatement) {
+ private GigiResultSet rs;
+
+ protected GigiPreparedStatement(PreparedStatement preparedStatement) {
target = preparedStatement;
}
+ public GigiPreparedStatement(String stmt) {
+ this(stmt, false);
+ }
+
+ public GigiPreparedStatement(String stmt, boolean scroll) {
+ try {
+ target = DatabaseConnection.getInstance().prepareInternal(stmt, scroll);
+ } catch (SQLException e) {
+ throw new Error(e);
+ }
+ }
+
public GigiResultSet executeQuery() {
try {
- return new GigiResultSet(target.executeQuery());
+ return rs = new GigiResultSet(target.executeQuery());
} catch (SQLException e) {
handleSQL(e);
throw new Error(e);
}
}
+ public void setEnum(int parameterIndex, DBEnum x) {
+ try {
+ target.setString(parameterIndex, x.getDBName());
+ } catch (SQLException e) {
+ handleSQL(e);
+ throw new Error(e);
+ }
+ }
+
public void setDate(int parameterIndex, Date x) {
try {
target.setDate(parameterIndex, x);
}
}
+ public int getParameterCount() {
+ try {
+ return target.getParameterMetaData().getParameterCount();
+ } catch (SQLException e) {
+ throw new Error(e);
+ }
+ }
+
private void handleSQL(SQLException e) {
// TODO Auto-generated method stub
}
+ @Override
+ public void close() {
+ GigiResultSet r = rs;
+ if (r != null) {
+ r.close();
+ }
+ PreparedStatement tg = target;
+ target = null;
+ try {
+ DatabaseConnection.getInstance().returnStatement(tg);
+ } catch (SQLException e) {
+ throw new Error(e);
+ }
+
+ }
+
}