| 1 | /* |
|---|
| 2 | * $Id$ |
|---|
| 3 | * |
|---|
| 4 | * Copyright 2006, The jCoderZ.org Project. All rights reserved. |
|---|
| 5 | * |
|---|
| 6 | * Redistribution and use in source and binary forms, with or without |
|---|
| 7 | * modification, are permitted provided that the following conditions are |
|---|
| 8 | * met: |
|---|
| 9 | * |
|---|
| 10 | * * Redistributions of source code must retain the above copyright |
|---|
| 11 | * notice, this list of conditions and the following disclaimer. |
|---|
| 12 | * * Redistributions in binary form must reproduce the above |
|---|
| 13 | * copyright notice, this list of conditions and the following |
|---|
| 14 | * disclaimer in the documentation and/or other materials |
|---|
| 15 | * provided with the distribution. |
|---|
| 16 | * * Neither the name of the jCoderZ.org Project nor the names of |
|---|
| 17 | * its contributors may be used to endorse or promote products |
|---|
| 18 | * derived from this software without specific prior written |
|---|
| 19 | * permission. |
|---|
| 20 | * |
|---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND |
|---|
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|---|
| 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS |
|---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|---|
| 28 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|---|
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|---|
| 30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|---|
| 31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 32 | */ |
|---|
| 33 | package org.jcoderz.commons.util; |
|---|
| 34 | |
|---|
| 35 | import java.io.InputStream; |
|---|
| 36 | import java.io.Reader; |
|---|
| 37 | import java.io.StringReader; |
|---|
| 38 | import java.math.BigDecimal; |
|---|
| 39 | import java.net.URL; |
|---|
| 40 | import java.sql.Array; |
|---|
| 41 | import java.sql.Blob; |
|---|
| 42 | import java.sql.Clob; |
|---|
| 43 | import java.sql.Connection; |
|---|
| 44 | import java.sql.Date; |
|---|
| 45 | import java.sql.Driver; |
|---|
| 46 | import java.sql.DriverManager; |
|---|
| 47 | import java.sql.ParameterMetaData; |
|---|
| 48 | import java.sql.PreparedStatement; |
|---|
| 49 | import java.sql.Ref; |
|---|
| 50 | import java.sql.ResultSet; |
|---|
| 51 | import java.sql.ResultSetMetaData; |
|---|
| 52 | import java.sql.SQLException; |
|---|
| 53 | import java.sql.SQLWarning; |
|---|
| 54 | import java.sql.Statement; |
|---|
| 55 | import java.sql.Time; |
|---|
| 56 | import java.sql.Timestamp; |
|---|
| 57 | import java.sql.Types; |
|---|
| 58 | import java.util.ArrayList; |
|---|
| 59 | import java.util.Calendar; |
|---|
| 60 | import java.util.Iterator; |
|---|
| 61 | import java.util.List; |
|---|
| 62 | import java.util.logging.Level; |
|---|
| 63 | import java.util.logging.Logger; |
|---|
| 64 | |
|---|
| 65 | /** |
|---|
| 66 | * Utility class for some DB routines. |
|---|
| 67 | * |
|---|
| 68 | * @author Albrecht Messner |
|---|
| 69 | */ |
|---|
| 70 | public final class DbUtil |
|---|
| 71 | { |
|---|
| 72 | /** class name for use in logger */ |
|---|
| 73 | private static final String CLASSNAME = DbUtil.class.getName(); |
|---|
| 74 | |
|---|
| 75 | /** logging facility */ |
|---|
| 76 | private static final Logger logger = Logger.getLogger(CLASSNAME); |
|---|
| 77 | |
|---|
| 78 | /** The oracle driver class for Oracle 8.x and 9.x */ |
|---|
| 79 | private static final String ORACLE_DRIVER_CLASSNAME |
|---|
| 80 | = "oracle.jdbc.OracleDriver"; |
|---|
| 81 | /** |
|---|
| 82 | * private constructor to avoid instantiation. |
|---|
| 83 | */ |
|---|
| 84 | private DbUtil () |
|---|
| 85 | { |
|---|
| 86 | // utility class -- no instances are allowed. |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | /** |
|---|
| 90 | * Close a statement according to resource handling idiom. |
|---|
| 91 | * @param stmt the statement to be closed |
|---|
| 92 | */ |
|---|
| 93 | public static void close (Statement stmt) |
|---|
| 94 | { |
|---|
| 95 | if (stmt != null) |
|---|
| 96 | { |
|---|
| 97 | try |
|---|
| 98 | { |
|---|
| 99 | stmt.close(); |
|---|
| 100 | } |
|---|
| 101 | catch (SQLException x) |
|---|
| 102 | { |
|---|
| 103 | logger.log(Level.FINE, "Error during resource cleanup: " |
|---|
| 104 | + "java.sql.Statement.close()", x); |
|---|
| 105 | } |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | /** |
|---|
| 110 | * Close a DB connection according to resource handling idiom. |
|---|
| 111 | * @param con the connection to be closed |
|---|
| 112 | */ |
|---|
| 113 | public static void close (Connection con) |
|---|
| 114 | { |
|---|
| 115 | if (con != null) |
|---|
| 116 | { |
|---|
| 117 | try |
|---|
| 118 | { |
|---|
| 119 | con.close(); |
|---|
| 120 | } |
|---|
| 121 | catch (SQLException x) |
|---|
| 122 | { |
|---|
| 123 | logger.log(Level.FINE, "Error during resource cleanup: " |
|---|
| 124 | + "java.sql.Connection.close()", x); |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | /** |
|---|
| 130 | * Close a result set according to resource handling idiom. |
|---|
| 131 | * @param resultSet the result set to close |
|---|
| 132 | */ |
|---|
| 133 | public static void close (ResultSet resultSet) |
|---|
| 134 | { |
|---|
| 135 | if (resultSet != null) |
|---|
| 136 | { |
|---|
| 137 | try |
|---|
| 138 | { |
|---|
| 139 | resultSet.close(); |
|---|
| 140 | } |
|---|
| 141 | catch (SQLException x) |
|---|
| 142 | { |
|---|
| 143 | logger.log(Level.FINE, "Error during resource cleanup: " |
|---|
| 144 | + "java.sql.ResultSet.close()", x); |
|---|
| 145 | } |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | /** |
|---|
| 150 | * Sets a parameter in a PreparedStatement to either a value or null. |
|---|
| 151 | * |
|---|
| 152 | * @param pstmt the prepared statement |
|---|
| 153 | * @param paramIndex the parameter index of the parameter to be set |
|---|
| 154 | * @param value the value to which the parameter must be set |
|---|
| 155 | * @throws SQLException if a database access error occurs. |
|---|
| 156 | */ |
|---|
| 157 | public static void setVarcharOrNull ( |
|---|
| 158 | PreparedStatement pstmt, int paramIndex, String value) |
|---|
| 159 | throws SQLException |
|---|
| 160 | { |
|---|
| 161 | setParameterOrNull(pstmt, paramIndex, value, Types.VARCHAR); |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | /** |
|---|
| 165 | * Sets a parameter in a PreparedStatement to either a value or null. |
|---|
| 166 | * |
|---|
| 167 | * @param pstmt the prepared statement |
|---|
| 168 | * @param paramIndex the parameter index of the parameter to be set |
|---|
| 169 | * @param value the value to which the parameter must be set |
|---|
| 170 | * @throws SQLException if a database access error occurs. |
|---|
| 171 | */ |
|---|
| 172 | public static void setCharOrNull ( |
|---|
| 173 | PreparedStatement pstmt, int paramIndex, String value) |
|---|
| 174 | throws SQLException |
|---|
| 175 | { |
|---|
| 176 | setParameterOrNull(pstmt, paramIndex, value, Types.CHAR); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | /** |
|---|
| 180 | * Sets a parameter in a PreparedStatement to either a value or null. |
|---|
| 181 | * |
|---|
| 182 | * @param pstmt the prepared statement |
|---|
| 183 | * @param paramIndex the parameter index of the parameter to be set |
|---|
| 184 | * @param value the value to which the parameter must be set |
|---|
| 185 | * @throws SQLException if a database access error occurs. |
|---|
| 186 | */ |
|---|
| 187 | public static void setClobOrNull ( |
|---|
| 188 | PreparedStatement pstmt, int paramIndex, String value) |
|---|
| 189 | throws SQLException |
|---|
| 190 | { |
|---|
| 191 | setParameterOrNull(pstmt, paramIndex, value, Types.CLOB); |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | /** |
|---|
| 195 | * Sets a parameter in a PreparedStatement to either a value or null. |
|---|
| 196 | * |
|---|
| 197 | * @param pstmt the prepared statement |
|---|
| 198 | * @param paramIndex the parameter index of the parameter to be set |
|---|
| 199 | * @param value the value to which the parameter must be set |
|---|
| 200 | * @throws SQLException if a database access error occurs. |
|---|
| 201 | */ |
|---|
| 202 | public static void setTimestampOrNull ( |
|---|
| 203 | PreparedStatement pstmt, int paramIndex, Timestamp value) |
|---|
| 204 | throws SQLException |
|---|
| 205 | { |
|---|
| 206 | setParameterOrNull(pstmt, paramIndex, value, Types.TIMESTAMP); |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | /** |
|---|
| 210 | * Sets a parameter in a PreparedStatement to either a value or null. |
|---|
| 211 | * |
|---|
| 212 | * @param pstmt the prepared statement |
|---|
| 213 | * @param paramIndex the parameter index of the parameter to be set |
|---|
| 214 | * @param value the value to which the parameter must be set |
|---|
| 215 | * @throws SQLException if a database access error occurs. |
|---|
| 216 | */ |
|---|
| 217 | public static void setIntegerOrNull ( |
|---|
| 218 | PreparedStatement pstmt, int paramIndex, Integer value) |
|---|
| 219 | throws SQLException |
|---|
| 220 | { |
|---|
| 221 | setParameterOrNull(pstmt, paramIndex, value, Types.INTEGER); |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | /** |
|---|
| 225 | * Sets a parameter in a PreparedStatement to either a value or null. |
|---|
| 226 | * |
|---|
| 227 | * @param pstmt the prepared statement |
|---|
| 228 | * @param paramIndex the parameter index of the parameter to be set |
|---|
| 229 | * @param value the value to which the parameter must be set |
|---|
| 230 | * @throws SQLException if a database access error occurs. |
|---|
| 231 | */ |
|---|
| 232 | public static void setLongOrNull ( |
|---|
| 233 | PreparedStatement pstmt, int paramIndex, Long value) |
|---|
| 234 | throws SQLException |
|---|
| 235 | { |
|---|
| 236 | // Sorry, can't delegate this one to setParameterOrNull because |
|---|
| 237 | // it's got a different type than setIntegerOrNull, but the same |
|---|
| 238 | // SQL type code. |
|---|
| 239 | if (value != null) |
|---|
| 240 | { |
|---|
| 241 | pstmt.setLong(paramIndex, value.longValue()); |
|---|
| 242 | } |
|---|
| 243 | else |
|---|
| 244 | { |
|---|
| 245 | pstmt.setNull(paramIndex, Types.INTEGER); |
|---|
| 246 | } |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | /** |
|---|
| 250 | * Registers the oracle JDBC driver. |
|---|
| 251 | * |
|---|
| 252 | * NOTE: only use either in testcases that need a direct JDBC connection |
|---|
| 253 | * or in stand-alone applications, never in the Application Server. |
|---|
| 254 | */ |
|---|
| 255 | public static void registerOracleDriver () |
|---|
| 256 | { |
|---|
| 257 | try |
|---|
| 258 | { |
|---|
| 259 | final Class driverClass |
|---|
| 260 | = Class.forName(ORACLE_DRIVER_CLASSNAME); |
|---|
| 261 | final Driver driverObject = (Driver) driverClass.newInstance(); |
|---|
| 262 | DriverManager.registerDriver(driverObject); |
|---|
| 263 | } |
|---|
| 264 | catch (Exception e) |
|---|
| 265 | { |
|---|
| 266 | final RuntimeException rte = new RuntimeException( |
|---|
| 267 | "Failed to register oracle driver " |
|---|
| 268 | + ORACLE_DRIVER_CLASSNAME, e); |
|---|
| 269 | throw rte; |
|---|
| 270 | } |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | /** |
|---|
| 274 | * This method wraps the {@link PreparedStatement} given as argument |
|---|
| 275 | * into a delegate object that calls the <code>executeBatch</code> |
|---|
| 276 | * method every <code>maxBatchSize</code>th time a batch is added to |
|---|
| 277 | * the statement with the <code>addBatch</code> method. |
|---|
| 278 | * |
|---|
| 279 | * @param pstmt the prepared statement to wrap |
|---|
| 280 | * @param maxBatchSize the maximum batch size at which an executeBatch |
|---|
| 281 | * should be called |
|---|
| 282 | * @return a PreparedStatement implementation that does automatic |
|---|
| 283 | * batch updates |
|---|
| 284 | */ |
|---|
| 285 | public static PreparedStatement getLimitedBatchSizePreparedStatement ( |
|---|
| 286 | PreparedStatement pstmt, int maxBatchSize) |
|---|
| 287 | { |
|---|
| 288 | return null; // new LimitedBatchSizePreparedStatement(pstmt, maxBatchSize); |
|---|
| 289 | } |
|---|
| 290 | |
|---|
| 291 | private static void setParameterOrNull ( |
|---|
| 292 | PreparedStatement pstmt, int paramIndex, Object value, int type) |
|---|
| 293 | throws SQLException |
|---|
| 294 | { |
|---|
| 295 | if (value != null) |
|---|
| 296 | { |
|---|
| 297 | switch (type) |
|---|
| 298 | { |
|---|
| 299 | case Types.VARCHAR: |
|---|
| 300 | case Types.CHAR: |
|---|
| 301 | pstmt.setString(paramIndex, (String) value); |
|---|
| 302 | break; |
|---|
| 303 | case Types.CLOB: |
|---|
| 304 | final String strVal = (String) value; |
|---|
| 305 | pstmt.setCharacterStream( |
|---|
| 306 | paramIndex, new StringReader(strVal), strVal.length()); |
|---|
| 307 | break; |
|---|
| 308 | case Types.TIMESTAMP: |
|---|
| 309 | final Timestamp tstampVal = (Timestamp) value; |
|---|
| 310 | pstmt.setTimestamp(paramIndex, tstampVal); |
|---|
| 311 | break; |
|---|
| 312 | case Types.INTEGER: |
|---|
| 313 | final Integer intVal = (Integer) value; |
|---|
| 314 | pstmt.setInt(paramIndex, intVal.intValue()); |
|---|
| 315 | break; |
|---|
| 316 | default: |
|---|
| 317 | throw new RuntimeException("Unexpected SQL type " |
|---|
| 318 | + type + " encountered"); |
|---|
| 319 | } |
|---|
| 320 | } |
|---|
| 321 | else |
|---|
| 322 | { |
|---|
| 323 | pstmt.setNull(paramIndex, type); |
|---|
| 324 | } |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | private static final class LimitedBatchSizePreparedStatement |
|---|
| 328 | // FIXME: does not work with JDK1.6.0 implements PreparedStatement |
|---|
| 329 | { |
|---|
| 330 | private final PreparedStatement mPreparedStatement; |
|---|
| 331 | private final int mMaxBatchSize; |
|---|
| 332 | private final List mResultList = new ArrayList(); |
|---|
| 333 | |
|---|
| 334 | private int mBatchCount = 0; |
|---|
| 335 | |
|---|
| 336 | private LimitedBatchSizePreparedStatement |
|---|
| 337 | (PreparedStatement pstmt, int maxBatchSize) |
|---|
| 338 | { |
|---|
| 339 | mPreparedStatement = pstmt; |
|---|
| 340 | mMaxBatchSize = maxBatchSize; |
|---|
| 341 | } |
|---|
| 342 | |
|---|
| 343 | /** {@inheritDoc} */ |
|---|
| 344 | public void addBatch () |
|---|
| 345 | throws SQLException |
|---|
| 346 | { |
|---|
| 347 | if (mBatchCount >= mMaxBatchSize) |
|---|
| 348 | { |
|---|
| 349 | internalExecuteBatch(); |
|---|
| 350 | } |
|---|
| 351 | mPreparedStatement.addBatch(); |
|---|
| 352 | mBatchCount++; |
|---|
| 353 | } |
|---|
| 354 | |
|---|
| 355 | /** {@inheritDoc} */ |
|---|
| 356 | public void addBatch (String sql) |
|---|
| 357 | throws SQLException |
|---|
| 358 | { |
|---|
| 359 | if (mBatchCount >= mMaxBatchSize) |
|---|
| 360 | { |
|---|
| 361 | internalExecuteBatch(); |
|---|
| 362 | } |
|---|
| 363 | mPreparedStatement.addBatch(sql); |
|---|
| 364 | mBatchCount++; |
|---|
| 365 | } |
|---|
| 366 | |
|---|
| 367 | /** {@inheritDoc} */ |
|---|
| 368 | public int[] executeBatch () |
|---|
| 369 | throws SQLException |
|---|
| 370 | { |
|---|
| 371 | internalExecuteBatch(); |
|---|
| 372 | |
|---|
| 373 | int totalBatchSize = 0; |
|---|
| 374 | for (final Iterator it = mResultList.iterator(); it.hasNext(); ) |
|---|
| 375 | { |
|---|
| 376 | final int[] updateResult = (int[]) it.next(); |
|---|
| 377 | totalBatchSize += updateResult.length; |
|---|
| 378 | } |
|---|
| 379 | |
|---|
| 380 | final int[] result = new int[totalBatchSize]; |
|---|
| 381 | int offset = 0; |
|---|
| 382 | for (final Iterator it = mResultList.iterator(); it.hasNext(); ) |
|---|
| 383 | { |
|---|
| 384 | final int[] updateResult = (int[]) it.next(); |
|---|
| 385 | System.arraycopy( |
|---|
| 386 | updateResult, 0, result, offset, updateResult.length); |
|---|
| 387 | offset += updateResult.length; |
|---|
| 388 | } |
|---|
| 389 | mResultList.clear(); |
|---|
| 390 | return result; |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | /** {@inheritDoc} */ |
|---|
| 394 | public void clearBatch () |
|---|
| 395 | throws SQLException |
|---|
| 396 | { |
|---|
| 397 | mPreparedStatement.clearBatch(); |
|---|
| 398 | mBatchCount = 0; |
|---|
| 399 | mResultList.clear(); |
|---|
| 400 | } |
|---|
| 401 | |
|---|
| 402 | /** {@inheritDoc} */ |
|---|
| 403 | public String toString () |
|---|
| 404 | { |
|---|
| 405 | return "[LimitedBatchSizePreparedStatement: mBatchSize=" |
|---|
| 406 | + mMaxBatchSize + ", mPreparedStatement=" |
|---|
| 407 | + mPreparedStatement + "]"; |
|---|
| 408 | } |
|---|
| 409 | |
|---|
| 410 | private void internalExecuteBatch () |
|---|
| 411 | throws SQLException |
|---|
| 412 | { |
|---|
| 413 | mBatchCount = 0; |
|---|
| 414 | final int[] result = mPreparedStatement.executeBatch(); |
|---|
| 415 | mResultList.add(result.clone()); |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | // ============================================================== |
|---|
| 419 | // only delegates below this point |
|---|
| 420 | // ============================================================== |
|---|
| 421 | |
|---|
| 422 | /** {@inheritDoc} */ |
|---|
| 423 | public void cancel () |
|---|
| 424 | throws SQLException |
|---|
| 425 | { |
|---|
| 426 | mPreparedStatement.cancel(); |
|---|
| 427 | } |
|---|
| 428 | |
|---|
| 429 | /** {@inheritDoc} */ |
|---|
| 430 | public void clearParameters () |
|---|
| 431 | throws SQLException |
|---|
| 432 | { |
|---|
| 433 | mPreparedStatement.clearParameters(); |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | /** {@inheritDoc} */ |
|---|
| 437 | public void clearWarnings () |
|---|
| 438 | throws SQLException |
|---|
| 439 | { |
|---|
| 440 | mPreparedStatement.clearWarnings(); |
|---|
| 441 | } |
|---|
| 442 | |
|---|
| 443 | /** {@inheritDoc} */ |
|---|
| 444 | public void close () |
|---|
| 445 | throws SQLException |
|---|
| 446 | { |
|---|
| 447 | mPreparedStatement.close(); |
|---|
| 448 | } |
|---|
| 449 | |
|---|
| 450 | /** {@inheritDoc} */ |
|---|
| 451 | public boolean execute () |
|---|
| 452 | throws SQLException |
|---|
| 453 | { |
|---|
| 454 | return mPreparedStatement.execute(); |
|---|
| 455 | } |
|---|
| 456 | |
|---|
| 457 | /** {@inheritDoc} */ |
|---|
| 458 | public boolean execute (String sql) |
|---|
| 459 | throws SQLException |
|---|
| 460 | { |
|---|
| 461 | return mPreparedStatement.execute(sql); |
|---|
| 462 | } |
|---|
| 463 | |
|---|
| 464 | /** {@inheritDoc} */ |
|---|
| 465 | public boolean execute (String sql, int autoGeneratedKeys) |
|---|
| 466 | throws SQLException |
|---|
| 467 | { |
|---|
| 468 | return mPreparedStatement.execute(sql, autoGeneratedKeys); |
|---|
| 469 | } |
|---|
| 470 | |
|---|
| 471 | /** {@inheritDoc} */ |
|---|
| 472 | public boolean execute (String sql, int[] columnIndexes) |
|---|
| 473 | throws SQLException |
|---|
| 474 | { |
|---|
| 475 | return mPreparedStatement.execute(sql, columnIndexes); |
|---|
| 476 | } |
|---|
| 477 | |
|---|
| 478 | /** {@inheritDoc} */ |
|---|
| 479 | public boolean execute (String sql, String[] columnNames) |
|---|
| 480 | throws SQLException |
|---|
| 481 | { |
|---|
| 482 | return mPreparedStatement.execute(sql, columnNames); |
|---|
| 483 | } |
|---|
| 484 | |
|---|
| 485 | /** {@inheritDoc} */ |
|---|
| 486 | public ResultSet executeQuery () |
|---|
| 487 | throws SQLException |
|---|
| 488 | { |
|---|
| 489 | return mPreparedStatement.executeQuery(); |
|---|
| 490 | } |
|---|
| 491 | |
|---|
| 492 | /** {@inheritDoc} */ |
|---|
| 493 | public ResultSet executeQuery (String sql) |
|---|
| 494 | throws SQLException |
|---|
| 495 | { |
|---|
| 496 | return mPreparedStatement.executeQuery(sql); |
|---|
| 497 | } |
|---|
| 498 | |
|---|
| 499 | /** {@inheritDoc} */ |
|---|
| 500 | public int executeUpdate () |
|---|
| 501 | throws SQLException |
|---|
| 502 | { |
|---|
| 503 | return mPreparedStatement.executeUpdate(); |
|---|
| 504 | } |
|---|
| 505 | |
|---|
| 506 | /** {@inheritDoc} */ |
|---|
| 507 | public int executeUpdate (String sql) |
|---|
| 508 | throws SQLException |
|---|
| 509 | { |
|---|
| 510 | return mPreparedStatement.executeUpdate(sql); |
|---|
| 511 | } |
|---|
| 512 | |
|---|
| 513 | /** {@inheritDoc} */ |
|---|
| 514 | public int executeUpdate (String sql, int autoGeneratedKeys) |
|---|
| 515 | throws SQLException |
|---|
| 516 | { |
|---|
| 517 | return mPreparedStatement.executeUpdate(sql, autoGeneratedKeys); |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | /** {@inheritDoc} */ |
|---|
| 521 | public int executeUpdate (String sql, int[] columnIndexes) |
|---|
| 522 | throws SQLException |
|---|
| 523 | { |
|---|
| 524 | return mPreparedStatement.executeUpdate(sql, columnIndexes); |
|---|
| 525 | } |
|---|
| 526 | |
|---|
| 527 | /** {@inheritDoc} */ |
|---|
| 528 | public int executeUpdate (String sql, String[] columnNames) |
|---|
| 529 | throws SQLException |
|---|
| 530 | { |
|---|
| 531 | return mPreparedStatement.executeUpdate(sql, columnNames); |
|---|
| 532 | } |
|---|
| 533 | |
|---|
| 534 | /** {@inheritDoc} */ |
|---|
| 535 | public Connection getConnection () |
|---|
| 536 | throws SQLException |
|---|
| 537 | { |
|---|
| 538 | return mPreparedStatement.getConnection(); |
|---|
| 539 | } |
|---|
| 540 | |
|---|
| 541 | /** {@inheritDoc} */ |
|---|
| 542 | public int getFetchDirection () |
|---|
| 543 | throws SQLException |
|---|
| 544 | { |
|---|
| 545 | return mPreparedStatement.getFetchDirection(); |
|---|
| 546 | } |
|---|
| 547 | |
|---|
| 548 | /** {@inheritDoc} */ |
|---|
| 549 | public int getFetchSize () |
|---|
| 550 | throws SQLException |
|---|
| 551 | { |
|---|
| 552 | return mPreparedStatement.getFetchSize(); |
|---|
| 553 | } |
|---|
| 554 | |
|---|
| 555 | /** {@inheritDoc} */ |
|---|
| 556 | public ResultSet getGeneratedKeys () |
|---|
| 557 | throws SQLException |
|---|
| 558 | { |
|---|
| 559 | return mPreparedStatement.getGeneratedKeys(); |
|---|
| 560 | } |
|---|
| 561 | |
|---|
| 562 | /** {@inheritDoc} */ |
|---|
| 563 | public int getMaxFieldSize () |
|---|
| 564 | throws SQLException |
|---|
| 565 | { |
|---|
| 566 | return mPreparedStatement.getMaxFieldSize(); |
|---|
| 567 | } |
|---|
| 568 | |
|---|
| 569 | /** {@inheritDoc} */ |
|---|
| 570 | public int getMaxRows () |
|---|
| 571 | throws SQLException |
|---|
| 572 | { |
|---|
| 573 | return mPreparedStatement.getMaxRows(); |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | /** {@inheritDoc} */ |
|---|
| 577 | public ResultSetMetaData getMetaData () |
|---|
| 578 | throws SQLException |
|---|
| 579 | { |
|---|
| 580 | return mPreparedStatement.getMetaData(); |
|---|
| 581 | } |
|---|
| 582 | |
|---|
| 583 | /** {@inheritDoc} */ |
|---|
| 584 | public boolean getMoreResults () |
|---|
| 585 | throws SQLException |
|---|
| 586 | { |
|---|
| 587 | return mPreparedStatement.getMoreResults(); |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | /** {@inheritDoc} */ |
|---|
| 591 | public boolean getMoreResults (int current) |
|---|
| 592 | throws SQLException |
|---|
| 593 | { |
|---|
| 594 | return mPreparedStatement.getMoreResults(current); |
|---|
| 595 | } |
|---|
| 596 | |
|---|
| 597 | /** {@inheritDoc} */ |
|---|
| 598 | public ParameterMetaData getParameterMetaData () |
|---|
| 599 | throws SQLException |
|---|
| 600 | { |
|---|
| 601 | return mPreparedStatement.getParameterMetaData(); |
|---|
| 602 | } |
|---|
| 603 | |
|---|
| 604 | /** {@inheritDoc} */ |
|---|
| 605 | public int getQueryTimeout () |
|---|
| 606 | throws SQLException |
|---|
| 607 | { |
|---|
| 608 | return mPreparedStatement.getQueryTimeout(); |
|---|
| 609 | } |
|---|
| 610 | |
|---|
| 611 | /** {@inheritDoc} */ |
|---|
| 612 | public ResultSet getResultSet () |
|---|
| 613 | throws SQLException |
|---|
| 614 | { |
|---|
| 615 | return mPreparedStatement.getResultSet(); |
|---|
| 616 | } |
|---|
| 617 | |
|---|
| 618 | /** {@inheritDoc} */ |
|---|
| 619 | public int getResultSetConcurrency () |
|---|
| 620 | throws SQLException |
|---|
| 621 | { |
|---|
| 622 | return mPreparedStatement.getResultSetConcurrency(); |
|---|
| 623 | } |
|---|
| 624 | |
|---|
| 625 | /** {@inheritDoc} */ |
|---|
| 626 | public int getResultSetHoldability () |
|---|
| 627 | throws SQLException |
|---|
| 628 | { |
|---|
| 629 | return mPreparedStatement.getResultSetHoldability(); |
|---|
| 630 | } |
|---|
| 631 | |
|---|
| 632 | /** {@inheritDoc} */ |
|---|
| 633 | public int getResultSetType () |
|---|
| 634 | throws SQLException |
|---|
| 635 | { |
|---|
| 636 | return mPreparedStatement.getResultSetType(); |
|---|
| 637 | } |
|---|
| 638 | |
|---|
| 639 | /** {@inheritDoc} */ |
|---|
| 640 | public int getUpdateCount () |
|---|
| 641 | throws SQLException |
|---|
| 642 | { |
|---|
| 643 | return mPreparedStatement.getUpdateCount(); |
|---|
| 644 | } |
|---|
| 645 | |
|---|
| 646 | /** {@inheritDoc} */ |
|---|
| 647 | public SQLWarning getWarnings () |
|---|
| 648 | throws SQLException |
|---|
| 649 | { |
|---|
| 650 | return mPreparedStatement.getWarnings(); |
|---|
| 651 | } |
|---|
| 652 | |
|---|
| 653 | /** {@inheritDoc} */ |
|---|
| 654 | public void setArray (int i, Array x) |
|---|
| 655 | throws SQLException |
|---|
| 656 | { |
|---|
| 657 | mPreparedStatement.setArray(i, x); |
|---|
| 658 | } |
|---|
| 659 | |
|---|
| 660 | /** {@inheritDoc} */ |
|---|
| 661 | public void setAsciiStream (int parameterIndex, InputStream x, int length) |
|---|
| 662 | throws SQLException |
|---|
| 663 | { |
|---|
| 664 | mPreparedStatement.setAsciiStream(parameterIndex, x, length); |
|---|
| 665 | } |
|---|
| 666 | |
|---|
| 667 | /** {@inheritDoc} */ |
|---|
| 668 | public void setBigDecimal (int parameterIndex, BigDecimal x) |
|---|
| 669 | throws SQLException |
|---|
| 670 | { |
|---|
| 671 | mPreparedStatement.setBigDecimal(parameterIndex, x); |
|---|
| 672 | } |
|---|
| 673 | |
|---|
| 674 | /** {@inheritDoc} */ |
|---|
| 675 | public void setBinaryStream ( |
|---|
| 676 | int parameterIndex, InputStream x, int length) |
|---|
| 677 | throws SQLException |
|---|
| 678 | { |
|---|
| 679 | mPreparedStatement.setBinaryStream(parameterIndex, x, length); |
|---|
| 680 | } |
|---|
| 681 | |
|---|
| 682 | /** {@inheritDoc} */ |
|---|
| 683 | public void setBlob (int i, Blob x) |
|---|
| 684 | throws SQLException |
|---|
| 685 | { |
|---|
| 686 | mPreparedStatement.setBlob(i, x); |
|---|
| 687 | } |
|---|
| 688 | |
|---|
| 689 | /** {@inheritDoc} */ |
|---|
| 690 | public void setBoolean (int parameterIndex, boolean x) |
|---|
| 691 | throws SQLException |
|---|
| 692 | { |
|---|
| 693 | mPreparedStatement.setBoolean(parameterIndex, x); |
|---|
| 694 | } |
|---|
| 695 | |
|---|
| 696 | /** {@inheritDoc} */ |
|---|
| 697 | public void setByte (int parameterIndex, byte x) |
|---|
| 698 | throws SQLException |
|---|
| 699 | { |
|---|
| 700 | mPreparedStatement.setByte(parameterIndex, x); |
|---|
| 701 | } |
|---|
| 702 | |
|---|
| 703 | /** {@inheritDoc} */ |
|---|
| 704 | public void setBytes (int parameterIndex, byte[] x) |
|---|
| 705 | throws SQLException |
|---|
| 706 | { |
|---|
| 707 | mPreparedStatement.setBytes(parameterIndex, x); |
|---|
| 708 | } |
|---|
| 709 | |
|---|
| 710 | /** {@inheritDoc} */ |
|---|
| 711 | public void setCharacterStream (int parameterIndex, Reader reader, |
|---|
| 712 | int length) |
|---|
| 713 | throws SQLException |
|---|
| 714 | { |
|---|
| 715 | mPreparedStatement.setCharacterStream(parameterIndex, reader, length); |
|---|
| 716 | } |
|---|
| 717 | |
|---|
| 718 | /** {@inheritDoc} */ |
|---|
| 719 | public void setClob (int i, Clob x) |
|---|
| 720 | throws SQLException |
|---|
| 721 | { |
|---|
| 722 | mPreparedStatement.setClob(i, x); |
|---|
| 723 | } |
|---|
| 724 | |
|---|
| 725 | /** {@inheritDoc} */ |
|---|
| 726 | public void setCursorName (String name) |
|---|
| 727 | throws SQLException |
|---|
| 728 | { |
|---|
| 729 | mPreparedStatement.setCursorName(name); |
|---|
| 730 | } |
|---|
| 731 | |
|---|
| 732 | /** {@inheritDoc} */ |
|---|
| 733 | public void setDate (int parameterIndex, Date x) |
|---|
| 734 | throws SQLException |
|---|
| 735 | { |
|---|
| 736 | mPreparedStatement.setDate(parameterIndex, x); |
|---|
| 737 | } |
|---|
| 738 | |
|---|
| 739 | /** {@inheritDoc} */ |
|---|
| 740 | public void setDate (int parameterIndex, Date x, Calendar cal) |
|---|
| 741 | throws SQLException |
|---|
| 742 | { |
|---|
| 743 | mPreparedStatement.setDate(parameterIndex, x, cal); |
|---|
| 744 | } |
|---|
| 745 | |
|---|
| 746 | /** {@inheritDoc} */ |
|---|
| 747 | public void setDouble (int parameterIndex, double x) |
|---|
| 748 | throws SQLException |
|---|
| 749 | { |
|---|
| 750 | mPreparedStatement.setDouble(parameterIndex, x); |
|---|
| 751 | } |
|---|
| 752 | |
|---|
| 753 | /** {@inheritDoc} */ |
|---|
| 754 | public void setEscapeProcessing (boolean enable) |
|---|
| 755 | throws SQLException |
|---|
| 756 | { |
|---|
| 757 | mPreparedStatement.setEscapeProcessing(enable); |
|---|
| 758 | } |
|---|
| 759 | |
|---|
| 760 | /** {@inheritDoc} */ |
|---|
| 761 | public void setFetchDirection (int direction) |
|---|
| 762 | throws SQLException |
|---|
| 763 | { |
|---|
| 764 | mPreparedStatement.setFetchDirection(direction); |
|---|
| 765 | } |
|---|
| 766 | |
|---|
| 767 | /** {@inheritDoc} */ |
|---|
| 768 | public void setFetchSize (int rows) |
|---|
| 769 | throws SQLException |
|---|
| 770 | { |
|---|
| 771 | mPreparedStatement.setFetchSize(rows); |
|---|
| 772 | } |
|---|
| 773 | |
|---|
| 774 | /** {@inheritDoc} */ |
|---|
| 775 | public void setFloat (int parameterIndex, float x) |
|---|
| 776 | throws SQLException |
|---|
| 777 | { |
|---|
| 778 | mPreparedStatement.setFloat(parameterIndex, x); |
|---|
| 779 | } |
|---|
| 780 | |
|---|
| 781 | /** {@inheritDoc} */ |
|---|
| 782 | public void setInt (int parameterIndex, int x) |
|---|
| 783 | throws SQLException |
|---|
| 784 | { |
|---|
| 785 | mPreparedStatement.setInt(parameterIndex, x); |
|---|
| 786 | } |
|---|
| 787 | |
|---|
| 788 | /** {@inheritDoc} */ |
|---|
| 789 | public void setLong (int parameterIndex, long x) |
|---|
| 790 | throws SQLException |
|---|
| 791 | { |
|---|
| 792 | mPreparedStatement.setLong(parameterIndex, x); |
|---|
| 793 | } |
|---|
| 794 | |
|---|
| 795 | /** {@inheritDoc} */ |
|---|
| 796 | public void setMaxFieldSize (int max) |
|---|
| 797 | throws SQLException |
|---|
| 798 | { |
|---|
| 799 | mPreparedStatement.setMaxFieldSize(max); |
|---|
| 800 | } |
|---|
| 801 | |
|---|
| 802 | /** {@inheritDoc} */ |
|---|
| 803 | public void setMaxRows (int max) |
|---|
| 804 | throws SQLException |
|---|
| 805 | { |
|---|
| 806 | mPreparedStatement.setMaxRows(max); |
|---|
| 807 | } |
|---|
| 808 | |
|---|
| 809 | /** {@inheritDoc} */ |
|---|
| 810 | public void setNull (int parameterIndex, int sqlType) |
|---|
| 811 | throws SQLException |
|---|
| 812 | { |
|---|
| 813 | mPreparedStatement.setNull(parameterIndex, sqlType); |
|---|
| 814 | } |
|---|
| 815 | |
|---|
| 816 | /** {@inheritDoc} */ |
|---|
| 817 | public void setNull (int paramIndex, int sqlType, String typeName) |
|---|
| 818 | throws SQLException |
|---|
| 819 | { |
|---|
| 820 | mPreparedStatement.setNull(paramIndex, sqlType, typeName); |
|---|
| 821 | } |
|---|
| 822 | |
|---|
| 823 | /** {@inheritDoc} */ |
|---|
| 824 | public void setObject (int parameterIndex, Object x) |
|---|
| 825 | throws SQLException |
|---|
| 826 | { |
|---|
| 827 | mPreparedStatement.setObject(parameterIndex, x); |
|---|
| 828 | } |
|---|
| 829 | |
|---|
| 830 | /** {@inheritDoc} */ |
|---|
| 831 | public void setObject (int parameterIndex, Object x, int targetSqlType) |
|---|
| 832 | throws SQLException |
|---|
| 833 | { |
|---|
| 834 | mPreparedStatement.setObject(parameterIndex, x, targetSqlType); |
|---|
| 835 | } |
|---|
| 836 | |
|---|
| 837 | /** {@inheritDoc} */ |
|---|
| 838 | public void setObject (int parameterIndex, Object x, int targetSqlType, |
|---|
| 839 | int scale) |
|---|
| 840 | throws SQLException |
|---|
| 841 | { |
|---|
| 842 | mPreparedStatement.setObject(parameterIndex, x, targetSqlType, scale); |
|---|
| 843 | } |
|---|
| 844 | |
|---|
| 845 | /** {@inheritDoc} */ |
|---|
| 846 | public void setQueryTimeout (int seconds) |
|---|
| 847 | throws SQLException |
|---|
| 848 | { |
|---|
| 849 | mPreparedStatement.setQueryTimeout(seconds); |
|---|
| 850 | } |
|---|
| 851 | |
|---|
| 852 | /** {@inheritDoc} */ |
|---|
| 853 | public void setRef (int i, Ref x) |
|---|
| 854 | throws SQLException |
|---|
| 855 | { |
|---|
| 856 | mPreparedStatement.setRef(i, x); |
|---|
| 857 | } |
|---|
| 858 | |
|---|
| 859 | /** {@inheritDoc} */ |
|---|
| 860 | public void setShort (int parameterIndex, short x) |
|---|
| 861 | throws SQLException |
|---|
| 862 | { |
|---|
| 863 | mPreparedStatement.setShort(parameterIndex, x); |
|---|
| 864 | } |
|---|
| 865 | |
|---|
| 866 | /** {@inheritDoc} */ |
|---|
| 867 | public void setString (int parameterIndex, String x) |
|---|
| 868 | throws SQLException |
|---|
| 869 | { |
|---|
| 870 | mPreparedStatement.setString(parameterIndex, x); |
|---|
| 871 | } |
|---|
| 872 | |
|---|
| 873 | /** {@inheritDoc} */ |
|---|
| 874 | public void setTime (int parameterIndex, Time x) |
|---|
| 875 | throws SQLException |
|---|
| 876 | { |
|---|
| 877 | mPreparedStatement.setTime(parameterIndex, x); |
|---|
| 878 | } |
|---|
| 879 | |
|---|
| 880 | /** {@inheritDoc} */ |
|---|
| 881 | public void setTime (int parameterIndex, Time x, Calendar cal) |
|---|
| 882 | throws SQLException |
|---|
| 883 | { |
|---|
| 884 | mPreparedStatement.setTime(parameterIndex, x, cal); |
|---|
| 885 | } |
|---|
| 886 | |
|---|
| 887 | /** {@inheritDoc} */ |
|---|
| 888 | public void setTimestamp (int parameterIndex, Timestamp x) |
|---|
| 889 | throws SQLException |
|---|
| 890 | { |
|---|
| 891 | mPreparedStatement.setTimestamp(parameterIndex, x); |
|---|
| 892 | } |
|---|
| 893 | |
|---|
| 894 | /** {@inheritDoc} */ |
|---|
| 895 | public void setTimestamp (int parameterIndex, Timestamp x, Calendar cal) |
|---|
| 896 | throws SQLException |
|---|
| 897 | { |
|---|
| 898 | mPreparedStatement.setTimestamp(parameterIndex, x, cal); |
|---|
| 899 | } |
|---|
| 900 | |
|---|
| 901 | /** {@inheritDoc} */ |
|---|
| 902 | public void setUnicodeStream (int parameterIndex, InputStream x, |
|---|
| 903 | int length) |
|---|
| 904 | throws SQLException |
|---|
| 905 | { |
|---|
| 906 | mPreparedStatement.setUnicodeStream(parameterIndex, x, length); |
|---|
| 907 | } |
|---|
| 908 | |
|---|
| 909 | /** {@inheritDoc} */ |
|---|
| 910 | public void setURL (int parameterIndex, URL x) |
|---|
| 911 | throws SQLException |
|---|
| 912 | { |
|---|
| 913 | mPreparedStatement.setURL(parameterIndex, x); |
|---|
| 914 | } |
|---|
| 915 | } |
|---|
| 916 | } |
|---|