1 16 17 package org.apache.commons.dbcp; 18 19 import java.math.BigDecimal ; 20 import java.sql.Array ; 21 import java.sql.Blob ; 22 import java.sql.Clob ; 23 import java.sql.PreparedStatement ; 24 import java.sql.Ref ; 25 import java.sql.ResultSet ; 26 import java.sql.ResultSetMetaData ; 27 import java.sql.SQLException ; 28 import java.util.Calendar ; 29 30 49 public class DelegatingPreparedStatement extends DelegatingStatement 50 implements PreparedStatement { 51 52 53 protected PreparedStatement _stmt = null; 54 55 63 public DelegatingPreparedStatement(DelegatingConnection c, 64 PreparedStatement s) { 65 super(c, s); 66 _stmt = s; 67 } 68 69 public boolean equals(Object obj) { 70 PreparedStatement delegate = (PreparedStatement ) getInnermostDelegate(); 71 if (delegate == null) { 72 return false; 73 } 74 if (obj instanceof DelegatingPreparedStatement) { 75 DelegatingPreparedStatement s = (DelegatingPreparedStatement) obj; 76 return delegate.equals(s.getInnermostDelegate()); 77 } 78 else { 79 return delegate.equals(obj); 80 } 81 } 82 83 84 public void setDelegate(PreparedStatement s) { 85 super.setDelegate(s); 86 _stmt = s; 87 } 88 89 public ResultSet executeQuery() throws SQLException { 90 checkOpen(); 91 try { 92 return DelegatingResultSet.wrapResultSet(this,_stmt.executeQuery()); 93 } 94 catch (SQLException e) { 95 handleException(e); 96 return null; 97 } 98 } 99 100 public int executeUpdate() throws SQLException 101 { checkOpen(); try { return _stmt.executeUpdate(); } catch (SQLException e) { handleException(e); return 0; } } 102 103 public void setNull(int parameterIndex, int sqlType) throws SQLException 104 { checkOpen(); try { _stmt.setNull(parameterIndex,sqlType); } catch (SQLException e) { handleException(e); } } 105 106 public void setBoolean(int parameterIndex, boolean x) throws SQLException 107 { checkOpen(); try { _stmt.setBoolean(parameterIndex,x); } catch (SQLException e) { handleException(e); } } 108 109 public void setByte(int parameterIndex, byte x) throws SQLException 110 { checkOpen(); try { _stmt.setByte(parameterIndex,x); } catch (SQLException e) { handleException(e); } } 111 112 public void setShort(int parameterIndex, short x) throws SQLException 113 { checkOpen(); try { _stmt.setShort(parameterIndex,x); } catch (SQLException e) { handleException(e); } } 114 115 public void setInt(int parameterIndex, int x) throws SQLException 116 { checkOpen(); try { _stmt.setInt(parameterIndex,x); } catch (SQLException e) { handleException(e); } } 117 118 public void setLong(int parameterIndex, long x) throws SQLException 119 { checkOpen(); try { _stmt.setLong(parameterIndex,x); } catch (SQLException e) { handleException(e); } } 120 121 public void setFloat(int parameterIndex, float x) throws SQLException 122 { checkOpen(); try { _stmt.setFloat(parameterIndex,x); } catch (SQLException e) { handleException(e); } } 123 124 public void setDouble(int parameterIndex, double x) throws SQLException 125 { checkOpen(); try { _stmt.setDouble(parameterIndex,x); } catch (SQLException e) { handleException(e); } } 126 127 public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException 128 { checkOpen(); try { _stmt.setBigDecimal(parameterIndex,x); } catch (SQLException e) { handleException(e); } } 129 130 public void setString(int parameterIndex, String x) throws SQLException 131 { checkOpen(); try { _stmt.setString(parameterIndex,x); } catch (SQLException e) { handleException(e); } } 132 133 public void setBytes(int parameterIndex, byte[] x) throws SQLException 134 { checkOpen(); try { _stmt.setBytes(parameterIndex,x); } catch (SQLException e) { handleException(e); } } 135 136 public void setDate(int parameterIndex, java.sql.Date x) throws SQLException 137 { checkOpen(); try { _stmt.setDate(parameterIndex,x); } catch (SQLException e) { handleException(e); } } 138 139 public void setTime(int parameterIndex, java.sql.Time x) throws SQLException 140 { checkOpen(); try { _stmt.setTime(parameterIndex,x); } catch (SQLException e) { handleException(e); } } 141 142 public void setTimestamp(int parameterIndex, java.sql.Timestamp x) throws SQLException 143 { checkOpen(); try { _stmt.setTimestamp(parameterIndex,x); } catch (SQLException e) { handleException(e); } } 144 145 public void setAsciiStream(int parameterIndex, java.io.InputStream x, int length) throws SQLException 146 { checkOpen(); try { _stmt.setAsciiStream(parameterIndex,x,length); } catch (SQLException e) { handleException(e); } } 147 148 149 public void setUnicodeStream(int parameterIndex, java.io.InputStream x, int length) throws SQLException 150 { checkOpen(); try { _stmt.setUnicodeStream(parameterIndex,x,length); } catch (SQLException e) { handleException(e); } } 151 152 public void setBinaryStream(int parameterIndex, java.io.InputStream x, int length) throws SQLException 153 { checkOpen(); try { _stmt.setBinaryStream(parameterIndex,x,length); } catch (SQLException e) { handleException(e); } } 154 155 public void clearParameters() throws SQLException 156 { checkOpen(); try { _stmt.clearParameters(); } catch (SQLException e) { handleException(e); } } 157 158 public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException 159 { checkOpen(); try { _stmt.setObject(parameterIndex, x, targetSqlType, scale); } catch (SQLException e) { handleException(e); } } 160 161 public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException 162 { checkOpen(); try { _stmt.setObject(parameterIndex, x, targetSqlType); } catch (SQLException e) { handleException(e); } } 163 164 public void setObject(int parameterIndex, Object x) throws SQLException 165 { checkOpen(); try { _stmt.setObject(parameterIndex, x); } catch (SQLException e) { handleException(e); } } 166 167 public boolean execute() throws SQLException 168 { checkOpen(); try { return _stmt.execute(); } catch (SQLException e) { handleException(e); return false; } } 169 170 public void addBatch() throws SQLException 171 { checkOpen(); try { _stmt.addBatch(); } catch (SQLException e) { handleException(e); } } 172 173 public void setCharacterStream(int parameterIndex, java.io.Reader reader, int length) throws SQLException 174 { checkOpen(); try { _stmt.setCharacterStream(parameterIndex,reader,length); } catch (SQLException e) { handleException(e); } } 175 176 public void setRef(int i, Ref x) throws SQLException 177 { checkOpen(); try { _stmt.setRef(i,x); } catch (SQLException e) { handleException(e); } } 178 179 public void setBlob(int i, Blob x) throws SQLException 180 { checkOpen(); try { _stmt.setBlob(i,x); } catch (SQLException e) { handleException(e); } } 181 182 public void setClob(int i, Clob x) throws SQLException 183 { checkOpen(); try { _stmt.setClob(i,x); } catch (SQLException e) { handleException(e); } } 184 185 public void setArray(int i, Array x) throws SQLException 186 { checkOpen(); try { _stmt.setArray(i,x); } catch (SQLException e) { handleException(e); } } 187 188 public ResultSetMetaData getMetaData() throws SQLException 189 { checkOpen(); try { return _stmt.getMetaData(); } catch (SQLException e) { handleException(e); return null; } } 190 191 public void setDate(int parameterIndex, java.sql.Date x, Calendar cal) throws SQLException 192 { checkOpen(); try { _stmt.setDate(parameterIndex,x,cal); } catch (SQLException e) { handleException(e); } } 193 194 public void setTime(int parameterIndex, java.sql.Time x, Calendar cal) throws SQLException 195 { checkOpen(); try { _stmt.setTime(parameterIndex,x,cal); } catch (SQLException e) { handleException(e); } } 196 197 public void setTimestamp(int parameterIndex, java.sql.Timestamp x, Calendar cal) throws SQLException 198 { checkOpen(); try { _stmt.setTimestamp(parameterIndex,x,cal); } catch (SQLException e) { handleException(e); } } 199 200 public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException 201 { checkOpen(); try { _stmt.setNull(paramIndex,sqlType,typeName); } catch (SQLException e) { handleException(e); } } 202 203 206 207 208 public void setURL(int parameterIndex, java.net.URL x) throws SQLException 209 { checkOpen(); try { _stmt.setURL(parameterIndex, x); } catch (SQLException e) { handleException(e); } } 210 211 public java.sql.ParameterMetaData getParameterMetaData() throws SQLException 212 { checkOpen(); try { return _stmt.getParameterMetaData(); } catch (SQLException e) { handleException(e); return null; } } 213 214 215 } 216 | Popular Tags |