X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fdatabase%2FGigiPreparedStatement.java;fp=src%2Forg%2Fcacert%2Fgigi%2Fdatabase%2FGigiPreparedStatement.java;h=81e5f4e31aa27004efb9df0468b1a2b31784b516;hb=3e123160ad59a2e1162518923965562ff947b6d1;hp=0000000000000000000000000000000000000000;hpb=68a4a5545da2d88ebcd83041c5e824bde81c3f38;p=gigi.git diff --git a/src/org/cacert/gigi/database/GigiPreparedStatement.java b/src/org/cacert/gigi/database/GigiPreparedStatement.java new file mode 100644 index 00000000..81e5f4e3 --- /dev/null +++ b/src/org/cacert/gigi/database/GigiPreparedStatement.java @@ -0,0 +1,106 @@ +package org.cacert.gigi.database; + +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; + +public class GigiPreparedStatement { + + PreparedStatement target; + + public GigiPreparedStatement(PreparedStatement preparedStatement) { + target = preparedStatement; + } + + public GigiResultSet executeQuery() { + try { + return new GigiResultSet(target.executeQuery()); + } catch (SQLException e) { + handleSQL(e); + throw new Error(e); + } + } + + public int executeUpdate() { + try { + return target.executeUpdate(); + } catch (SQLException e) { + handleSQL(e); + throw new Error(e); + } + } + + public boolean execute() { + try { + return target.execute(); + } catch (SQLException e) { + handleSQL(e); + throw new Error(e); + } + } + + public void setInt(int parameterIndex, int x) { + try { + target.setInt(parameterIndex, x); + } catch (SQLException e) { + handleSQL(e); + throw new Error(e); + } + } + + public void setString(int parameterIndex, String x) { + try { + target.setString(parameterIndex, x); + } catch (SQLException e) { + handleSQL(e); + throw new Error(e); + } + } + + public void setDate(int parameterIndex, Date x) { + try { + target.setDate(parameterIndex, x); + } catch (SQLException e) { + handleSQL(e); + throw new Error(e); + } + } + + public void setTimestamp(int parameterIndex, Timestamp x) { + try { + target.setTimestamp(parameterIndex, x); + } catch (SQLException e) { + handleSQL(e); + throw new Error(e); + } + } + + public int lastInsertId() { + try { + ResultSet rs = target.getGeneratedKeys(); + rs.next(); + int id = rs.getInt(1); + rs.close(); + return id; + } catch (SQLException e) { + handleSQL(e); + throw new Error(e); + } + } + + public void setBoolean(int parameterIndex, boolean x) { + try { + target.setBoolean(parameterIndex, x); + } catch (SQLException e) { + handleSQL(e); + throw new Error(e); + } + } + + private void handleSQL(SQLException e) { + // TODO Auto-generated method stub + + } +}