0001: /**
0002: * JOnAS: Java(TM) Open Application Server
0003: * Copyright (C) 1999-2005 Bull S.A.
0004: * Contact: jonas-team@objectweb.org
0005: *
0006: *
0007: * This library is free software; you can redistribute it and/or
0008: * modify it under the terms of the GNU Lesser General Public
0009: * License as published by the Free Software Foundation; either
0010: * version 2 of the License, or (at your option) any later version.
0011: *
0012: * This library is distributed in the hope that it will be useful,
0013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0015: * Lesser General Public License for more details.
0016: *
0017: * You should have received a copy of the GNU Lesser General Public
0018: * License along with this library; if not, write to the Free Software
0019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0020: *
0021: * --------------------------------------------------------------------------
0022: * $Id: PreparedStatementWrapper.java 6728 2005-05-09 16:26:28Z benoitf $
0023: * --------------------------------------------------------------------------
0024: *
0025: */package org.objectweb.jonas.resource;
0026:
0027: import java.io.InputStream;
0028: import java.io.Reader;
0029: import java.math.BigDecimal;
0030: import java.net.URL;
0031: import java.sql.Array;
0032: import java.sql.Blob;
0033: import java.sql.Clob;
0034: import java.sql.Connection;
0035: import java.sql.Date;
0036: import java.sql.ParameterMetaData;
0037: import java.sql.PreparedStatement;
0038: import java.sql.Ref;
0039: import java.sql.ResultSet;
0040: import java.sql.ResultSetMetaData;
0041: import java.sql.SQLException;
0042: import java.sql.SQLWarning;
0043: import java.sql.Time;
0044: import java.sql.Timestamp;
0045: import java.util.Arrays;
0046: import java.util.Calendar;
0047:
0048: import org.objectweb.util.monolog.api.BasicLevel;
0049: import org.objectweb.util.monolog.api.Logger;
0050:
0051: /**
0052: * This class <b>PreparedStatementWrapper</b> wrapp an SQL PreparedStatement
0053: * @author Eric HARDESTY
0054: */
0055: public class PreparedStatementWrapper implements PreparedStatement {
0056:
0057: /**
0058: * Prime numbers
0059: */
0060: private static final int[] PRIME_NUMBERS = new int[] { 11, 13, 17,
0061: 19, 23, 29, 31, 37, 41, 43, 47 };
0062:
0063: /**
0064: * Wrapped preparedstatement object
0065: */
0066: private PreparedStatement pstmt = null;
0067:
0068: /**
0069: * User used for the preparedstatement
0070: */
0071: private String user = null;
0072:
0073: /**
0074: * SQL statement
0075: */
0076: private String sql = null;
0077:
0078: /**
0079: * This object has been marked invalid ?
0080: */
0081: private boolean invalid = false;
0082:
0083: /**
0084: * This object is now closed ?
0085: */
0086: private boolean closed = false;
0087:
0088: /**
0089: * Hashcode of this object
0090: */
0091: private int hashCode;
0092:
0093: /**
0094: * Type of result set. one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
0095: * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
0096: * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
0097: */
0098: private int resultSetType = -1;
0099:
0100: /**
0101: * Concurrency type for result set; one of
0102: * <code>ResultSet.CONCUR_READ_ONLY</code> or
0103: * <code>ResultSet.CONCUR_UPDATABLE</code>
0104: */
0105: private int resultSetConcurrency = -1;
0106:
0107: /**
0108: * Holdability, One of the value :
0109: * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
0110: * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
0111: */
0112: private int resultSetHoldability = -1;
0113:
0114: /**
0115: * A flag indicating whether auto-generated keys should be returned; one of
0116: * <code>Statement.RETURN_GENERATED_KEYS</code> or
0117: * <code>Statement.NO_GENERATED_KEYS</code>
0118: */
0119: private int autoGeneratedKeys = -1;
0120:
0121: /**
0122: * An array of column indexes indicating the columns that should be returned
0123: * from the inserted row or rows
0124: */
0125: private int[] columnIndexes = null;
0126:
0127: /**
0128: * An array of column names indicating the columns that should be returned
0129: * from the inserted row or rows
0130: */
0131: private String[] columnNames = null;
0132:
0133: /**
0134: * Logger used for traces
0135: */
0136: private final Logger trace;
0137:
0138: /**
0139: * Direction was Changed ? need to reset or not
0140: */
0141: private boolean setFetchDirectionCalled = false;
0142:
0143: /**
0144: * Escape processing was changed ? need to reset or not
0145: */
0146: private boolean setEscapeProcessingCalled = false;
0147:
0148: /**
0149: * Max field size ? need to reset or not
0150: */
0151: private boolean setMaxFieldSizeCalled = false;
0152:
0153: /**
0154: * Debug logging enabled ?
0155: */
0156: private final boolean isDebugLogging;
0157:
0158: /**
0159: * Creates a <code>PreparedStatementWrapper</code> object.
0160: * This constructor is private and is used by other constructors.
0161: * It contains all constructors elements.
0162: * @param user the user used for accessing the connection
0163: * @param sql a <code>String</code> object that is the SQL statement to be
0164: * sent to the database; may contain one or more ? IN parameters
0165: * @param resultSetType a result set type; one of
0166: * <code>ResultSet.TYPE_FORWARD_ONLY</code>,
0167: * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
0168: * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
0169: * @param resultSetConcurrency a concurrency type; one of
0170: * <code>ResultSet.CONCUR_READ_ONLY</code> or
0171: * <code>ResultSet.CONCUR_UPDATABLE</code>
0172: * @param resultSetHoldability one of the following <code>ResultSet</code>
0173: * constants: <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
0174: * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
0175: * @param autoGeneratedKeys a flag indicating whether auto-generated keys
0176: * should be returned; one of
0177: * <code>Statement.RETURN_GENERATED_KEYS</code> or
0178: * <code>Statement.NO_GENERATED_KEYS</code>
0179: * @param columnIndexes an array of column indexes indicating the columns
0180: * that should be returned from the inserted row or rows
0181: * @param columnNames an array of column names indicating the columns that
0182: * should be returned from the inserted row or rows
0183: * @param trace the logger to use for logging purpose
0184: * @param isDebugLogging if true, log the debug event in the logger
0185: */
0186: private PreparedStatementWrapper(final String user,
0187: final String sql, final int resultSetType,
0188: final int resultSetConcurrency,
0189: final int resultSetHoldability,
0190: final int autoGeneratedKeys, final int[] columnIndexes,
0191: final String[] columnNames, final Logger trace,
0192: final boolean isDebugLogging) {
0193:
0194: this .user = user;
0195: this .sql = sql;
0196: this .resultSetType = resultSetType;
0197: this .resultSetConcurrency = resultSetConcurrency;
0198: this .resultSetHoldability = resultSetHoldability;
0199: this .autoGeneratedKeys = autoGeneratedKeys;
0200: this .columnIndexes = columnIndexes;
0201: this .columnNames = columnNames;
0202: this .trace = trace;
0203:
0204: int i = 0;
0205: // hashcode computing
0206: if (sql != null) {
0207: hashCode = sql.hashCode();
0208: } else {
0209: hashCode = PRIME_NUMBERS[i++];
0210: }
0211: if (user != null) {
0212: hashCode ^= user.hashCode();
0213: } else {
0214: hashCode ^= PRIME_NUMBERS[i++];
0215: }
0216: hashCode ^= (resultSetType * PRIME_NUMBERS[i++]);
0217: hashCode ^= (resultSetConcurrency * PRIME_NUMBERS[i++]);
0218: hashCode ^= (resultSetHoldability * PRIME_NUMBERS[i++]);
0219: hashCode ^= (autoGeneratedKeys * PRIME_NUMBERS[i++]);
0220: if (columnIndexes != null) {
0221: hashCode ^= columnIndexes.hashCode();
0222: } else {
0223: hashCode ^= PRIME_NUMBERS[i++];
0224: }
0225: if (columnNames != null) {
0226: hashCode ^= columnNames.hashCode();
0227: } else {
0228: hashCode ^= PRIME_NUMBERS[i++];
0229: }
0230: this .isDebugLogging = isDebugLogging;
0231: }
0232:
0233: /**
0234: * Creates a <code>PreparedStatementWrapper</code> object that will
0235: * generate <code>ResultSet</code> objects with the given type and
0236: * concurrency. This method is the same as the <code>prepareStatement</code>
0237: * method above, but it allows the default result set type and concurrency
0238: * to be overridden.
0239: * @param user the user used for accessing the connection
0240: * @param sql a <code>String</code> object that is the SQL statement to be
0241: * sent to the database; may contain one or more ? IN parameters
0242: * @param resultSetType a result set type; one of
0243: * <code>ResultSet.TYPE_FORWARD_ONLY</code>,
0244: * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
0245: * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
0246: * @param resultSetConcurrency a concurrency type; one of
0247: * <code>ResultSet.CONCUR_READ_ONLY</code> or
0248: * <code>ResultSet.CONCUR_UPDATABLE</code>
0249: * @param trace the logger to use for logging purpose
0250: * @param isDebugLogging if true, log the debug event in the logger
0251: * @since JDK 1.2
0252: */
0253: public PreparedStatementWrapper(final String user,
0254: final String sql, final int resultSetType,
0255: final int resultSetConcurrency, final Logger trace,
0256: final boolean isDebugLogging) {
0257: this (user, sql, resultSetType, resultSetConcurrency, -1, -1,
0258: null, null, trace, isDebugLogging);
0259: }
0260:
0261: /**
0262: * Creates a <code>PreparedStatementWrapper</code> object that will
0263: * generate <code>ResultSet</code> objects with the given type,
0264: * concurrency, and holdability.
0265: * <P>
0266: * This method is the same as the <code>prepareStatement</code> method
0267: * above, but it allows the default result set type, concurrency, and
0268: * holdability to be overridden.
0269: * @param user the user used for accessing the connection
0270: * @param sql a <code>String</code> object that is the SQL statement to be
0271: * sent to the database; may contain one or more ? IN parameters
0272: * @param resultSetType one of the following <code>ResultSet</code>
0273: * constants: <code>ResultSet.TYPE_FORWARD_ONLY</code>,
0274: * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
0275: * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
0276: * @param resultSetConcurrency one of the following <code>ResultSet</code>
0277: * constants: <code>ResultSet.CONCUR_READ_ONLY</code> or
0278: * <code>ResultSet.CONCUR_UPDATABLE</code>
0279: * @param resultSetHoldability one of the following <code>ResultSet</code>
0280: * constants: <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
0281: * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
0282: * @param trace the logger to use for logging purpose
0283: * @param isDebugLogging if true, log the debug event in the logger
0284: * @since JDK 1.4
0285: */
0286: public PreparedStatementWrapper(final String user,
0287: final String sql, final int resultSetType,
0288: final int resultSetConcurrency,
0289: final int resultSetHoldability, final Logger trace,
0290: final boolean isDebugLogging) {
0291: this (user, sql, resultSetType, resultSetConcurrency,
0292: resultSetHoldability, -1, null, null, trace,
0293: isDebugLogging);
0294: }
0295:
0296: /**
0297: * Creates a default <code>PreparedStatementWrapper</code> object that has
0298: * the capability to retrieve auto-generated keys. The given constant tells
0299: * the driver whether it should make auto-generated keys available for
0300: * retrieval. This parameter is ignored if the SQL statement is not an
0301: * <code>INSERT</code> statement.
0302: * @param user the user used for accessing the connection
0303: * @param sql an SQL statement that may contain one or more '?' IN parameter
0304: * placeholders
0305: * @param autoGeneratedKeys a flag indicating whether auto-generated keys
0306: * should be returned; one of
0307: * <code>Statement.RETURN_GENERATED_KEYS</code> or
0308: * <code>Statement.NO_GENERATED_KEYS</code>
0309: * @param trace the logger to use for logging purpose
0310: * @param isDebugLogging if true, log the debug event in the logger
0311: * @since JDK 1.4
0312: */
0313: public PreparedStatementWrapper(final String user,
0314: final String sql, final int autoGeneratedKeys,
0315: final Logger trace, final boolean isDebugLogging) {
0316: this (user, sql, -1, -1, -1, autoGeneratedKeys, null, null,
0317: trace, isDebugLogging);
0318: }
0319:
0320: /**
0321: * Creates a default <code>PreparedStatementWrapper</code> object capable
0322: * of returning the auto-generated keys designated by the given array. This
0323: * array contains the indexes of the columns in the target table that
0324: * contain the auto-generated keys that should be made available. This array
0325: * is ignored if the SQL statement is not an <code>INSERT</code>
0326: * statement.
0327: * <P>
0328: * An SQL statement with or without IN parameters can be pre-compiled and
0329: * stored in a <code>PreparedStatement</code> object. This object can then
0330: * be used to efficiently execute this statement multiple times.
0331: * @param user the user used for accessing the connection
0332: * @param sql an SQL statement that may contain one or more '?' IN parameter
0333: * placeholders
0334: * @param columnIndexes an array of column indexes indicating the columns
0335: * that should be returned from the inserted row or rows
0336: * @param trace the logger to use for logging purpose
0337: * @param isDebugLogging if true, log the debug event in the logger
0338: * @since JDK 1.4
0339: */
0340: public PreparedStatementWrapper(final String user,
0341: final String sql, final int[] columnIndexes,
0342: final Logger trace, final boolean isDebugLogging) {
0343: this (user, sql, -1, -1, -1, -1, columnIndexes, null, trace,
0344: isDebugLogging);
0345: }
0346:
0347: /**
0348: * Creates a default <code>PreparedStatementWrapper</code> object capable
0349: * of returning the auto-generated keys designated by the given array. This
0350: * array contains the names of the columns in the target table that contain
0351: * the auto-generated keys that should be returned. This array is ignored if
0352: * the SQL statement is not an <code>INSERT</code> statement.
0353: * <P>
0354: * An SQL statement with or without IN parameters can be pre-compiled and
0355: * stored in a <code>PreparedStatement</code> object. This object can then
0356: * be used to efficiently execute this statement multiple times.
0357: * @param user the user used for accessing the connection
0358: * @param sql an SQL statement that may contain one or more '?' IN parameter
0359: * placeholders
0360: * @param columnNames an array of column names indicating the columns that
0361: * should be returned from the inserted row or rows
0362: * @param trace the logger to use for logging purpose
0363: * @param isDebugLogging if true, log the debug event in the logger
0364: * @since JDK 1.4
0365: */
0366: public PreparedStatementWrapper(final String user,
0367: final String sql, final String[] columnNames,
0368: final Logger trace, final boolean isDebugLogging) {
0369: this (user, sql, -1, -1, -1, -1, null, columnNames, trace,
0370: isDebugLogging);
0371: }
0372:
0373: /**
0374: * Checks that this object is not in invalid state
0375: * @throws SQLException if object is in invalid mode
0376: */
0377: public void checkIfValid() throws SQLException {
0378: if (invalid) {
0379: SQLException se = new SQLException("PreparedStatement("
0380: + this + ") is invalid.");
0381: trace.log(BasicLevel.ERROR, se);
0382: throw se;
0383: }
0384:
0385: }
0386:
0387: /**
0388: * Clears the values stored in the preparement. This is required as this
0389: * preparedstatement is reused
0390: */
0391: public void clearPstmtValues() {
0392: closed = false;
0393: try {
0394: pstmt.clearParameters();
0395: pstmt.clearBatch();
0396: } catch (Throwable ex) {
0397: if (isDebugLogging) {
0398: trace.log(BasicLevel.DEBUG, "Cannot clear parameters",
0399: ex);
0400: }
0401: }
0402: if (setEscapeProcessingCalled) {
0403: try {
0404: pstmt.setEscapeProcessing(true);
0405: } catch (Throwable ex) {
0406: if (isDebugLogging) {
0407: trace.log(BasicLevel.DEBUG,
0408: "Cannot reset escape processing to true",
0409: ex);
0410: }
0411: }
0412: }
0413: if (setFetchDirectionCalled) {
0414: try {
0415: pstmt.setFetchDirection(ResultSet.FETCH_FORWARD);
0416: } catch (Throwable ex) {
0417: if (isDebugLogging) {
0418: trace
0419: .log(
0420: BasicLevel.DEBUG,
0421: "Cannot set fetch direction to ResultSet.FETCH_FORWARD",
0422: ex);
0423: }
0424: }
0425: }
0426: if (setMaxFieldSizeCalled) {
0427: try {
0428: pstmt.setMaxFieldSize(0);
0429: } catch (Throwable ex) {
0430: if (isDebugLogging) {
0431: trace.log(BasicLevel.DEBUG,
0432: "Cannot set max field size to 0", ex);
0433: }
0434: }
0435: }
0436: try {
0437: pstmt.setMaxRows(0);
0438: } catch (Throwable ex) {
0439: if (isDebugLogging) {
0440: trace.log(BasicLevel.DEBUG, "Cannot set max rows to 0",
0441: ex);
0442: }
0443: }
0444: try {
0445: pstmt.setQueryTimeout(0);
0446: } catch (Throwable ex) {
0447: if (isDebugLogging) {
0448: trace.log(BasicLevel.DEBUG,
0449: "Cannot set query timeout to 0", ex);
0450: }
0451: }
0452: try {
0453: pstmt.clearWarnings();
0454: } catch (Throwable ex) {
0455: if (isDebugLogging) {
0456: trace
0457: .log(BasicLevel.DEBUG, "Cannot clear warnings",
0458: ex);
0459: }
0460: }
0461: }
0462:
0463: /**
0464: * Close this object
0465: * @throws SQLException if object cannot be closed
0466: */
0467: public void closePstmt() throws SQLException {
0468: closed = true;
0469: pstmt.close();
0470: }
0471:
0472: /**
0473: * Destroy this preparestatement object, then it becomes closed and invalid
0474: * @throws SQLException if it cannot be closed
0475: */
0476: public void destroy() throws SQLException {
0477: if (isDebugLogging) {
0478: trace.log(BasicLevel.DEBUG, "" + this );
0479: }
0480: try {
0481: pstmt.close();
0482: } finally {
0483: invalid = true;
0484: closed = true;
0485: }
0486: }
0487:
0488: /**
0489: * @param stmt given statement for comparing it
0490: * @return true if given object is equals to this current object
0491: */
0492: public boolean equals(Object stmt) {
0493: if (stmt == null) {
0494: return false;
0495: }
0496: // different hashcode, cannot be equals
0497: if (this .hashCode != stmt.hashCode()) {
0498: return false;
0499: }
0500:
0501: // if got same hashcode, try to see if cast is ok.
0502: if (!(stmt instanceof PreparedStatementWrapper)) {
0503: return false;
0504: }
0505: PreparedStatementWrapper psw = (PreparedStatementWrapper) stmt;
0506:
0507: if (invalid) {
0508: if (isDebugLogging) {
0509: trace.log(BasicLevel.DEBUG,
0510: "Prepared Statement is invalid");
0511: }
0512: return false;
0513: }
0514: if (sql == null && psw.sql != null) {
0515: if (isDebugLogging) {
0516: trace.log(BasicLevel.DEBUG, "Stmt sql: " + psw.sql
0517: + " not equal to " + sql);
0518: }
0519: return false;
0520: }
0521: if (sql != null && !sql.equals(psw.sql)) {
0522: if (isDebugLogging) {
0523: trace.log(BasicLevel.DEBUG, "Stmt sql: " + psw.sql
0524: + " not equal to " + sql);
0525: }
0526: return false;
0527: }
0528: if (user == null && psw.user != null) {
0529: if (isDebugLogging) {
0530: trace.log(BasicLevel.DEBUG, "Stmt user: " + psw.user
0531: + " not equal to " + user);
0532: }
0533: return false;
0534: }
0535: if (user != null && !user.equals(psw.user)) {
0536: if (isDebugLogging) {
0537: trace.log(BasicLevel.DEBUG, "Stmt user: " + psw.user
0538: + " not equal to " + user);
0539: }
0540: return false;
0541: }
0542: if (resultSetType != psw.resultSetType) {
0543: if (isDebugLogging) {
0544: trace.log(BasicLevel.DEBUG, "Stmt resultSetType: "
0545: + psw.resultSetType + " not equal to "
0546: + resultSetType);
0547: }
0548: return false;
0549: }
0550: if (resultSetConcurrency != psw.resultSetConcurrency) {
0551: if (isDebugLogging) {
0552: trace.log(BasicLevel.DEBUG,
0553: "Stmt resultSetConcurrency: "
0554: + psw.resultSetConcurrency
0555: + " not equal to "
0556: + resultSetConcurrency);
0557: }
0558: return false;
0559: }
0560: if (resultSetHoldability != psw.resultSetHoldability) {
0561: if (isDebugLogging) {
0562: trace.log(BasicLevel.DEBUG,
0563: "Stmt resultSetHoldability: "
0564: + psw.resultSetHoldability
0565: + " not equal to "
0566: + resultSetHoldability);
0567: }
0568: return false;
0569: }
0570: if (autoGeneratedKeys != psw.autoGeneratedKeys) {
0571: if (isDebugLogging) {
0572: trace.log(BasicLevel.DEBUG, "Stmt autoGeneratedKeys: "
0573: + psw.autoGeneratedKeys + " not equal to "
0574: + autoGeneratedKeys);
0575: }
0576: return false;
0577: }
0578: if (!Arrays.equals(columnIndexes, psw.columnIndexes)) {
0579: if (isDebugLogging) {
0580: trace.log(BasicLevel.DEBUG, "Stmt columnIndexes: "
0581: + psw.columnIndexes + " not equal to "
0582: + columnIndexes);
0583: }
0584: return false;
0585: }
0586: if (!Arrays.equals(columnNames, psw.columnNames)) {
0587: if (isDebugLogging) {
0588: trace.log(BasicLevel.DEBUG, "Stmt columnNames: "
0589: + psw.columnNames + " not equal to "
0590: + columnNames);
0591: }
0592: return false;
0593: }
0594: if (isDebugLogging) {
0595: trace.log(BasicLevel.DEBUG, "Stmt found at " + this );
0596: }
0597: return true;
0598: }
0599:
0600: /**
0601: * Close this object
0602: * @param val true/false
0603: */
0604: public void setClosed(boolean val) {
0605: closed = val;
0606: }
0607:
0608: /**
0609: * Sets the real prepared statement object on which we wrap calls
0610: * @param pstmt sql preparedstatement
0611: */
0612: public void setPreparedStatement(PreparedStatement pstmt) {
0613: this .pstmt = pstmt;
0614: }
0615:
0616: /***************************************************************************
0617: * Prepared Statment calls
0618: */
0619:
0620: /**
0621: * Adds a set of parameters to this <code>PreparedStatement</code>
0622: * object's batch of commands.
0623: * @exception SQLException if a database access error occurs
0624: * @see Statement#addBatch
0625: * @since 1.2
0626: */
0627: public void addBatch() throws SQLException {
0628: checkIfValid();
0629: pstmt.addBatch();
0630: }
0631:
0632: /**
0633: * Clears the current parameter values immediately.
0634: * <P>
0635: * In general, parameter values remain in force for repeated use of a
0636: * statement. Setting a parameter value automatically clears its previous
0637: * value. However, in some cases it is useful to immediately release the
0638: * resources used by the current parameter values; this can be done by
0639: * calling the method <code>clearParameters</code>.
0640: * @exception SQLException if a database access error occurs
0641: */
0642: public void clearParameters() throws SQLException {
0643: checkIfValid();
0644: pstmt.clearParameters();
0645: }
0646:
0647: /**
0648: * Executes the SQL statement in this <code>PreparedStatement</code>
0649: * object, which may be any kind of SQL statement. Some prepared statements
0650: * return multiple results; the <code>execute</code> method handles these
0651: * complex statements as well as the simpler form of statements handled by
0652: * the methods <code>executeQuery</code> and <code>executeUpdate</code>.
0653: * <P>
0654: * The <code>execute</code> method returns a <code>boolean</code> to
0655: * indicate the form of the first result. You must call either the method
0656: * <code>getResultSet</code> or <code>getUpdateCount</code> to retrieve
0657: * the result; you must call <code>getMoreResults</code> to move to any
0658: * subsequent result(s).
0659: * @return <code>true</code> if the first result is a
0660: * <code>ResultSet</code> object; <code>false</code> if the
0661: * first result is an update count or there is no result
0662: * @exception SQLException if a database access error occurs or an argument
0663: * is supplied to this method
0664: * @see Statement#execute
0665: * @see Statement#getResultSet
0666: * @see Statement#getUpdateCount
0667: * @see Statement#getMoreResults
0668: */
0669: public boolean execute() throws SQLException {
0670: checkIfValid();
0671: return pstmt.execute();
0672: }
0673:
0674: // JDK1.4
0675: /**
0676: * Executes the given SQL statement, which may return multiple results, and
0677: * signals the driver that any auto-generated keys should be made available
0678: * for retrieval. The driver will ignore this signal if the SQL statement is
0679: * not an <code>INSERT</code> statement.
0680: * <P>
0681: * In some (uncommon) situations, a single SQL statement may return multiple
0682: * result sets and/or update counts. Normally you can ignore this unless you
0683: * are (1) executing a stored procedure that you know may return multiple
0684: * results or (2) you are dynamically executing an unknown SQL string.
0685: * <P>
0686: * The <code>execute</code> method executes an SQL statement and indicates
0687: * the form of the first result. You must then use the methods
0688: * <code>getResultSet</code> or <code>getUpdateCount</code> to retrieve
0689: * the result, and <code>getMoreResults</code> to move to any subsequent
0690: * result(s).
0691: * @param sql any SQL statement
0692: * @param autoGeneratedKeys a constant indicating whether auto-generated
0693: * keys should be made available for retrieval using the method
0694: * <code>getGeneratedKeys</code>; one of the following constants:
0695: * <code>Statement.RETURN_GENERATED_KEYS</code> or
0696: * <code>Statement.NO_GENERATED_KEYS</code>
0697: * @return <code>true</code> if the first result is a
0698: * <code>ResultSet</code> object; <code>false</code> if it is an
0699: * update count or there are no results
0700: * @exception SQLException if a database access error occurs or the second
0701: * parameter supplied to this method is not
0702: * <code>Statement.RETURN_GENERATED_KEYS</code> or
0703: * <code>Statement.NO_GENERATED_KEYS</code>.
0704: * @see #getResultSet
0705: * @see #getUpdateCount
0706: * @see #getMoreResults
0707: * @see #getGeneratedKeys
0708: * @since 1.4
0709: */
0710: public boolean execute(String sql, int autoGeneratedKeys)
0711: throws SQLException {
0712: checkIfValid();
0713: return pstmt.execute(sql, autoGeneratedKeys);
0714: }
0715:
0716: // JDK1.4
0717: /**
0718: * Executes the given SQL statement, which may return multiple results, and
0719: * signals the driver that the auto-generated keys indicated in the given
0720: * array should be made available for retrieval. This array contains the
0721: * indexes of the columns in the target table that contain the
0722: * auto-generated keys that should be made available. The driver will ignore
0723: * the array if the given SQL statement is not an <code>INSERT</code>
0724: * statement.
0725: * <P>
0726: * Under some (uncommon) situations, a single SQL statement may return
0727: * multiple result sets and/or update counts. Normally you can ignore this
0728: * unless you are (1) executing a stored procedure that you know may return
0729: * multiple results or (2) you are dynamically executing an unknown SQL
0730: * string.
0731: * <P>
0732: * The <code>execute</code> method executes an SQL statement and indicates
0733: * the form of the first result. You must then use the methods
0734: * <code>getResultSet</code> or <code>getUpdateCount</code> to retrieve
0735: * the result, and <code>getMoreResults</code> to move to any subsequent
0736: * result(s).
0737: * @param sql any SQL statement
0738: * @param columnIndexes an array of the indexes of the columns in the
0739: * inserted row that should be made available for retrieval by a call
0740: * to the method <code>getGeneratedKeys</code>
0741: * @return <code>true</code> if the first result is a
0742: * <code>ResultSet</code> object; <code>false</code> if it is an
0743: * update count or there are no results
0744: * @exception SQLException if a database access error occurs or the elements
0745: * in the <code>int</code> array passed to this method are not
0746: * valid column indexes
0747: * @see #getResultSet
0748: * @see #getUpdateCount
0749: * @see #getMoreResults
0750: * @since 1.4
0751: */
0752: public boolean execute(String sql, int[] columnIndexes)
0753: throws SQLException {
0754: checkIfValid();
0755: return pstmt.execute(sql, columnIndexes);
0756: }
0757:
0758: // JDK1.4
0759: /**
0760: * Executes the given SQL statement, which may return multiple results, and
0761: * signals the driver that the auto-generated keys indicated in the given
0762: * array should be made available for retrieval. This array contains the
0763: * names of the columns in the target table that contain the auto-generated
0764: * keys that should be made available. The driver will ignore the array if
0765: * the given SQL statement is not an <code>INSERT</code> statement.
0766: * <P>
0767: * In some (uncommon) situations, a single SQL statement may return multiple
0768: * result sets and/or update counts. Normally you can ignore this unless you
0769: * are (1) executing a stored procedure that you know may return multiple
0770: * results or (2) you are dynamically executing an unknown SQL string.
0771: * <P>
0772: * The <code>execute</code> method executes an SQL statement and indicates
0773: * the form of the first result. You must then use the methods
0774: * <code>getResultSet</code> or <code>getUpdateCount</code> to retrieve
0775: * the result, and <code>getMoreResults</code> to move to any subsequent
0776: * result(s).
0777: * @param sql any SQL statement
0778: * @param columnNames an array of the names of the columns in the inserted
0779: * row that should be made available for retrieval by a call to the
0780: * method <code>getGeneratedKeys</code>
0781: * @return <code>true</code> if the next result is a
0782: * <code>ResultSet</code> object; <code>false</code> if it is an
0783: * update count or there are no more results
0784: * @exception SQLException if a database access error occurs or the elements
0785: * of the <code>String</code> array passed to this method are
0786: * not valid column names
0787: * @see #getResultSet
0788: * @see #getUpdateCount
0789: * @see #getMoreResults
0790: * @see #getGeneratedKeys
0791: * @since 1.4
0792: */
0793: public boolean execute(String sql, String[] columnNames)
0794: throws SQLException {
0795: checkIfValid();
0796: return pstmt.execute(sql, columnNames);
0797: }
0798:
0799: /**
0800: * Executes the SQL query in this <code>PreparedStatement</code> object
0801: * and returns the <code>ResultSet</code> object generated by the query.
0802: * @return a <code>ResultSet</code> object that contains the data produced
0803: * by the query; never <code>null</code>
0804: * @exception SQLException if a database access error occurs or the SQL
0805: * statement does not return a <code>ResultSet</code> object
0806: */
0807: public ResultSet executeQuery() throws SQLException {
0808: checkIfValid();
0809: return pstmt.executeQuery();
0810: }
0811:
0812: /**
0813: * Executes the SQL statement in this <code>PreparedStatement</code>
0814: * object, which must be an SQL <code>INSERT</code>, <code>UPDATE</code>
0815: * or <code>DELETE</code> statement; or an SQL statement that returns
0816: * nothing, such as a DDL statement.
0817: * @return either (1) the row count for <code>INSERT</code>,
0818: * <code>UPDATE</code>, or <code>DELETE</code> statements or
0819: * (2) 0 for SQL statements that return nothing
0820: * @exception SQLException if a database access error occurs or the SQL
0821: * statement returns a <code>ResultSet</code> object
0822: */
0823: public int executeUpdate() throws SQLException {
0824: checkIfValid();
0825: return pstmt.executeUpdate();
0826: }
0827:
0828: // JDK1.4
0829: /**
0830: * Executes the given SQL statement and signals the driver with the given
0831: * flag about whether the auto-generated keys produced by this
0832: * <code>Statement</code> object should be made available for retrieval.
0833: * @param sql must be an SQL <code>INSERT</code>, <code>UPDATE</code>
0834: * or <code>DELETE</code> statement or an SQL statement that
0835: * returns nothing
0836: * @param autoGeneratedKeys a flag indicating whether auto-generated keys
0837: * should be made available for retrieval; one of the following
0838: * constants: <code>Statement.RETURN_GENERATED_KEYS</code>
0839: * <code>Statement.NO_GENERATED_KEYS</code>
0840: * @return either the row count for <code>INSERT</code>,
0841: * <code>UPDATE</code> or <code>DELETE</code> statements, or
0842: * <code>0</code> for SQL statements that return nothing
0843: * @exception SQLException if a database access error occurs, the given SQL
0844: * statement returns a <code>ResultSet</code> object, or the
0845: * given constant is not one of those allowed
0846: * @since 1.4
0847: */
0848: public int executeUpdate(String sql, int autoGeneratedKeys)
0849: throws SQLException {
0850: checkIfValid();
0851: return pstmt.executeUpdate(sql, autoGeneratedKeys);
0852: }
0853:
0854: // JDK1.4
0855: /**
0856: * Executes the given SQL statement and signals the driver that the
0857: * auto-generated keys indicated in the given array should be made available
0858: * for retrieval. The driver will ignore the array if the SQL statement is
0859: * not an <code>INSERT</code> statement.
0860: * @param sql an SQL <code>INSERT</code>, <code>UPDATE</code> or
0861: * <code>DELETE</code> statement or an SQL statement that returns
0862: * nothing, such as an SQL DDL statement
0863: * @param columnIndexes an array of column indexes indicating the columns
0864: * that should be returned from the inserted row
0865: * @return either the row count for <code>INSERT</code>,
0866: * <code>UPDATE</code>, or <code>DELETE</code> statements, or 0
0867: * for SQL statements that return nothing
0868: * @exception SQLException if a database access error occurs, the SQL
0869: * statement returns a <code>ResultSet</code> object, or the
0870: * second argument supplied to this method is not an
0871: * <code>int</code> array whose elements are valid column
0872: * indexes
0873: * @since 1.4
0874: */
0875: public int executeUpdate(String sql, int[] columnIndexes)
0876: throws SQLException {
0877: checkIfValid();
0878: return pstmt.executeUpdate(sql, columnIndexes);
0879: }
0880:
0881: // JDK1.4
0882: /**
0883: * Executes the given SQL statement and signals the driver that the
0884: * auto-generated keys indicated in the given array should be made available
0885: * for retrieval. The driver will ignore the array if the SQL statement is
0886: * not an <code>INSERT</code> statement.
0887: * @param sql an SQL <code>INSERT</code>, <code>UPDATE</code> or
0888: * <code>DELETE</code> statement or an SQL statement that returns
0889: * nothing
0890: * @param columnNames an array of the names of the columns that should be
0891: * returned from the inserted row
0892: * @return either the row count for <code>INSERT</code>,
0893: * <code>UPDATE</code>, or <code>DELETE</code> statements, or 0
0894: * for SQL statements that return nothing
0895: * @exception SQLException if a database access error occurs, the SQL
0896: * statement returns a <code>ResultSet</code> object, or the
0897: * second argument supplied to this method is not a
0898: * <code>String</code> array whose elements are valid column
0899: * names
0900: * @since 1.4
0901: */
0902: public int executeUpdate(String sql, String[] columnNames)
0903: throws SQLException {
0904: checkIfValid();
0905: return pstmt.executeUpdate(sql, columnNames);
0906: }
0907:
0908: // JDK1.4
0909: /**
0910: * Retrieves any auto-generated keys created as a result of executing this
0911: * <code>Statement</code> object. If this <code>Statement</code> object
0912: * did not generate any keys, an empty <code>ResultSet</code> object is
0913: * returned.
0914: * @return a <code>ResultSet</code> object containing the auto-generated
0915: * key(s) generated by the execution of this <code>Statement</code>
0916: * object
0917: * @exception SQLException if a database access error occurs
0918: * @since 1.4
0919: */
0920: public ResultSet getGeneratedKeys() throws SQLException {
0921: checkIfValid();
0922: return pstmt.getGeneratedKeys();
0923: }
0924:
0925: /**
0926: * Retrieves a <code>ResultSetMetaData</code> object that contains
0927: * information about the columns of the <code>ResultSet</code> object that
0928: * will be returned when this <code>PreparedStatement</code> object is
0929: * executed.
0930: * <P>
0931: * Because a <code>PreparedStatement</code> object is precompiled, it is
0932: * possible to know about the <code>ResultSet</code> object that it will
0933: * return without having to execute it. Consequently, it is possible to
0934: * invoke the method <code>getMetaData</code> on a
0935: * <code>PreparedStatement</code> object rather than waiting to execute it
0936: * and then invoking the <code>ResultSet.getMetaData</code> method on the
0937: * <code>ResultSet</code> object that is returned.
0938: * <P>
0939: * <B>NOTE:</B> Using this method may be expensive for some drivers due to
0940: * the lack of underlying DBMS support.
0941: * @return the description of a <code>ResultSet</code> object's columns or
0942: * <code>null</code> if the driver cannot return a
0943: * <code>ResultSetMetaData</code> object
0944: * @exception SQLException if a database access error occurs
0945: * @since 1.2
0946: */
0947: public ResultSetMetaData getMetaData() throws SQLException {
0948: checkIfValid();
0949: return pstmt.getMetaData();
0950: }
0951:
0952: // JDK1.4
0953: /**
0954: * Moves to this <code>Statement</code> object's next result, deals with
0955: * any current <code>ResultSet</code> object(s) according to the
0956: * instructions specified by the given flag, and returns <code>true</code>
0957: * if the next result is a <code>ResultSet</code> object.
0958: * <P>
0959: * There are no more results when the following is true:
0960: *
0961: * <PRE> // stmt is a Statement object ((stmt.getMoreResults() == false) &&
0962: * (stmt.getUpdateCount() == -1))
0963: *
0964: * </PRE>
0965: *
0966: * @param current one of the following <code>Statement</code> constants
0967: * indicating what should happen to current <code>ResultSet</code>
0968: * objects obtained using the method <code>getResultSet</code>:
0969: * <code>Statement.CLOSE_CURRENT_RESULT</code>,
0970: * <code>Statement.KEEP_CURRENT_RESULT</code>, or
0971: * <code>Statement.CLOSE_ALL_RESULTS</code>
0972: * @return <code>true</code> if the next result is a
0973: * <code>ResultSet</code> object; <code>false</code> if it is an
0974: * update count or there are no more results
0975: * @exception SQLException if a database access error occurs or the argument
0976: * supplied is not one of the following:
0977: * <code>Statement.CLOSE_CURRENT_RESULT</code>,
0978: * <code>Statement.KEEP_CURRENT_RESULT</code>, or
0979: * <code>Statement.CLOSE_ALL_RESULTS</code>
0980: * @since 1.4
0981: * @see #execute
0982: */
0983: public boolean getMoreResults(int current) throws SQLException {
0984: checkIfValid();
0985: return pstmt.getMoreResults(current);
0986:
0987: }
0988:
0989: // JDK1.4
0990: /**
0991: * Retrieves the number, types and properties of this
0992: * <code>PreparedStatement</code> object's parameters.
0993: * @return a <code>ParameterMetaData</code> object that contains
0994: * information about the number, types and properties of this
0995: * <code>PreparedStatement</code> object's parameters
0996: * @exception SQLException if a database access error occurs
0997: * @see ParameterMetaData
0998: * @since 1.4
0999: */
1000: public ParameterMetaData getParameterMetaData() throws SQLException {
1001: checkIfValid();
1002: return pstmt.getParameterMetaData();
1003:
1004: }
1005:
1006: // JDK1.4
1007: /**
1008: * Retrieves the result set holdability for <code>ResultSet</code> objects
1009: * generated by this <code>Statement</code> object.
1010: * @return either <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
1011: * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
1012: * @exception SQLException if a database access error occurs
1013: * @since 1.4
1014: */
1015: public int getResultSetHoldability() throws SQLException {
1016: checkIfValid();
1017: return pstmt.getResultSetHoldability();
1018: }
1019:
1020: /**
1021: * Sets the designated parameter to the given <code>Array</code> object.
1022: * The driver converts this to an SQL <code>ARRAY</code> value when it
1023: * sends it to the database.
1024: * @param i the first parameter is 1, the second is 2, ...
1025: * @param x an <code>Array</code> object that maps an SQL
1026: * <code>ARRAY</code> value
1027: * @exception SQLException if a database access error occurs
1028: * @since 1.2
1029: */
1030: public void setArray(int i, Array x) throws SQLException {
1031: checkIfValid();
1032: pstmt.setArray(i, x);
1033: }
1034:
1035: /**
1036: * Sets the designated parameter to the given input stream, which will have
1037: * the specified number of bytes. When a very large ASCII value is input to
1038: * a <code>LONGVARCHAR</code> parameter, it may be more practical to send
1039: * it via a <code>java.io.InputStream</code>. Data will be read from the
1040: * stream as needed until end-of-file is reached. The JDBC driver will do
1041: * any necessary conversion from ASCII to the database char format.
1042: * <P>
1043: * <B>Note:</B> This stream object can either be a standard Java stream
1044: * object or your own subclass that implements the standard interface.
1045: * @param parameterIndex the first parameter is 1, the second is 2, ...
1046: * @param x the Java input stream that contains the ASCII parameter value
1047: * @param length the number of bytes in the stream
1048: * @exception SQLException if a database access error occurs
1049: */
1050: public void setAsciiStream(int parameterIndex, InputStream x,
1051: int length) throws SQLException {
1052: checkIfValid();
1053: pstmt.setAsciiStream(parameterIndex, x, length);
1054:
1055: }
1056:
1057: /**
1058: * Sets the designated parameter to the given
1059: * <code>java.math.BigDecimal</code> value. The driver converts this to an
1060: * SQL <code>NUMERIC</code> value when it sends it to the database.
1061: * @param parameterIndex the first parameter is 1, the second is 2, ...
1062: * @param x the parameter value
1063: * @exception SQLException if a database access error occurs
1064: */
1065: public void setBigDecimal(int parameterIndex, BigDecimal x)
1066: throws SQLException {
1067: checkIfValid();
1068: pstmt.setBigDecimal(parameterIndex, x);
1069: }
1070:
1071: /**
1072: * Sets the designated parameter to the given input stream, which will have
1073: * the specified number of bytes. When a very large binary value is input to
1074: * a <code>LONGVARBINARY</code> parameter, it may be more practical to
1075: * send it via a <code>java.io.InputStream</code> object. The data will be
1076: * read from the stream as needed until end-of-file is reached.
1077: * <P>
1078: * <B>Note:</B> This stream object can either be a standard Java stream
1079: * object or your own subclass that implements the standard interface.
1080: * @param parameterIndex the first parameter is 1, the second is 2, ...
1081: * @param x the java input stream which contains the binary parameter value
1082: * @param length the number of bytes in the stream
1083: * @exception SQLException if a database access error occurs
1084: */
1085: public void setBinaryStream(int parameterIndex, InputStream x,
1086: int length) throws SQLException {
1087: checkIfValid();
1088: pstmt.setBinaryStream(parameterIndex, x, length);
1089: }
1090:
1091: /**
1092: * Sets the designated parameter to the given <code>Blob</code> object.
1093: * The driver converts this to an SQL <code>BLOB</code> value when it
1094: * sends it to the database.
1095: * @param i the first parameter is 1, the second is 2, ...
1096: * @param x a <code>Blob</code> object that maps an SQL <code>BLOB</code>
1097: * value
1098: * @exception SQLException if a database access error occurs
1099: * @since 1.2
1100: */
1101: public void setBlob(int i, Blob x) throws SQLException {
1102: checkIfValid();
1103: pstmt.setBlob(i, x);
1104: }
1105:
1106: /**
1107: * Sets the designated parameter to the given Java <code>boolean</code>
1108: * value. The driver converts this to an SQL <code>BIT</code> value when
1109: * it sends it to the database.
1110: * @param parameterIndex the first parameter is 1, the second is 2, ...
1111: * @param x the parameter value
1112: * @exception SQLException if a database access error occurs
1113: */
1114: public void setBoolean(int parameterIndex, boolean x)
1115: throws SQLException {
1116: checkIfValid();
1117: pstmt.setBoolean(parameterIndex, x);
1118: }
1119:
1120: /**
1121: * Sets the designated parameter to the given Java <code>byte</code>
1122: * value. The driver converts this to an SQL <code>TINYINT</code> value
1123: * when it sends it to the database.
1124: * @param parameterIndex the first parameter is 1, the second is 2, ...
1125: * @param x the parameter value
1126: * @exception SQLException if a database access error occurs
1127: */
1128: public void setByte(int parameterIndex, byte x) throws SQLException {
1129: checkIfValid();
1130: pstmt.setByte(parameterIndex, x);
1131: }
1132:
1133: /**
1134: * Sets the designated parameter to the given Java array of bytes. The
1135: * driver converts this to an SQL <code>VARBINARY</code> or
1136: * <code>LONGVARBINARY</code> (depending on the argument's size relative
1137: * to the driver's limits on <code>VARBINARY</code> values) when it sends
1138: * it to the database.
1139: * @param parameterIndex the first parameter is 1, the second is 2, ...
1140: * @param x the parameter value
1141: * @exception SQLException if a database access error occurs
1142: */
1143: public void setBytes(int parameterIndex, byte[] x)
1144: throws SQLException {
1145: checkIfValid();
1146: pstmt.setBytes(parameterIndex, x);
1147: }
1148:
1149: /**
1150: * Sets the designated parameter to the given <code>Reader</code> object,
1151: * which is the given number of characters long. When a very large UNICODE
1152: * value is input to a <code>LONGVARCHAR</code> parameter, it may be more
1153: * practical to send it via a <code>java.io.Reader</code> object. The data
1154: * will be read from the stream as needed until end-of-file is reached. The
1155: * JDBC driver will do any necessary conversion from UNICODE to the database
1156: * char format.
1157: * <P>
1158: * <B>Note:</B> This stream object can either be a standard Java stream
1159: * object or your own subclass that implements the standard interface.
1160: * @param parameterIndex the first parameter is 1, the second is 2, ...
1161: * @param reader the <code>java.io.Reader</code> object that contains the
1162: * Unicode data
1163: * @param length the number of characters in the stream
1164: * @exception SQLException if a database access error occurs
1165: * @since 1.2
1166: */
1167: public void setCharacterStream(int parameterIndex, Reader reader,
1168: int length) throws SQLException {
1169: checkIfValid();
1170: pstmt.setCharacterStream(parameterIndex, reader, length);
1171: }
1172:
1173: /**
1174: * Sets the designated parameter to the given <code>Clob</code> object.
1175: * The driver converts this to an SQL <code>CLOB</code> value when it
1176: * sends it to the database.
1177: * @param i the first parameter is 1, the second is 2, ...
1178: * @param x a <code>Clob</code> object that maps an SQL <code>CLOB</code>
1179: * value
1180: * @exception SQLException if a database access error occurs
1181: * @since 1.2
1182: */
1183: public void setClob(int i, Clob x) throws SQLException {
1184: checkIfValid();
1185: pstmt.setClob(i, x);
1186: }
1187:
1188: /**
1189: * Sets the designated parameter to the given <code>java.sql.Date</code>
1190: * value. The driver converts this to an SQL <code>DATE</code> value when
1191: * it sends it to the database.
1192: * @param parameterIndex the first parameter is 1, the second is 2, ...
1193: * @param x the parameter value
1194: * @exception SQLException if a database access error occurs
1195: */
1196: public void setDate(int parameterIndex, Date x) throws SQLException {
1197: checkIfValid();
1198: pstmt.setDate(parameterIndex, x);
1199: }
1200:
1201: /**
1202: * Sets the designated parameter to the given <code>java.sql.Date</code>
1203: * value, using the given <code>Calendar</code> object. The driver uses
1204: * the <code>Calendar</code> object to construct an SQL <code>DATE</code>
1205: * value, which the driver then sends to the database. With a
1206: * <code>Calendar</code> object, the driver can calculate the date taking
1207: * into account a custom timezone. If no <code>Calendar</code> object is
1208: * specified, the driver uses the default timezone, which is that of the
1209: * virtual machine running the application.
1210: * @param parameterIndex the first parameter is 1, the second is 2, ...
1211: * @param x the parameter value
1212: * @param cal the <code>Calendar</code> object the driver will use to
1213: * construct the date
1214: * @exception SQLException if a database access error occurs
1215: * @since 1.2
1216: */
1217: public void setDate(int parameterIndex, Date x, Calendar cal)
1218: throws SQLException {
1219: checkIfValid();
1220: pstmt.setDate(parameterIndex, x, cal);
1221: }
1222:
1223: /**
1224: * Sets the designated parameter to the given Java <code>double</code>
1225: * value. The driver converts this to an SQL <code>DOUBLE</code> value
1226: * when it sends it to the database.
1227: * @param parameterIndex the first parameter is 1, the second is 2, ...
1228: * @param x the parameter value
1229: * @exception SQLException if a database access error occurs
1230: */
1231: public void setDouble(int parameterIndex, double x)
1232: throws SQLException {
1233: checkIfValid();
1234: pstmt.setDouble(parameterIndex, x);
1235: }
1236:
1237: /**
1238: * Sets the designated parameter to the given Java <code>float</code>
1239: * value. The driver converts this to an SQL <code>FLOAT</code> value when
1240: * it sends it to the database.
1241: * @param parameterIndex the first parameter is 1, the second is 2, ...
1242: * @param x the parameter value
1243: * @exception SQLException if a database access error occurs
1244: */
1245: public void setFloat(int parameterIndex, float x)
1246: throws SQLException {
1247: checkIfValid();
1248: pstmt.setFloat(parameterIndex, x);
1249: }
1250:
1251: /**
1252: * Sets the designated parameter to the given Java <code>int</code> value.
1253: * The driver converts this to an SQL <code>INTEGER</code> value when it
1254: * sends it to the database.
1255: * @param parameterIndex the first parameter is 1, the second is 2, ...
1256: * @param x the parameter value
1257: * @exception SQLException if a database access error occurs
1258: */
1259: public void setInt(int parameterIndex, int x) throws SQLException {
1260: checkIfValid();
1261: pstmt.setInt(parameterIndex, x);
1262: }
1263:
1264: /**
1265: * Sets the designated parameter to the given Java <code>long</code>
1266: * value. The driver converts this to an SQL <code>BIGINT</code> value
1267: * when it sends it to the database.
1268: * @param parameterIndex the first parameter is 1, the second is 2, ...
1269: * @param x the parameter value
1270: * @exception SQLException if a database access error occurs
1271: */
1272: public void setLong(int parameterIndex, long x) throws SQLException {
1273: checkIfValid();
1274: pstmt.setLong(parameterIndex, x);
1275: }
1276:
1277: /**
1278: * Sets the designated parameter to SQL <code>NULL</code>.
1279: * <P>
1280: * <B>Note:</B> You must specify the parameter's SQL type.
1281: * @param parameterIndex the first parameter is 1, the second is 2, ...
1282: * @param sqlType the SQL type code defined in <code>java.sql.Types</code>
1283: * @exception SQLException if a database access error occurs
1284: */
1285: public void setNull(int parameterIndex, int sqlType)
1286: throws SQLException {
1287: checkIfValid();
1288: pstmt.setNull(parameterIndex, sqlType);
1289: }
1290:
1291: /**
1292: * Sets the designated parameter to SQL <code>NULL</code>. This version
1293: * of the method <code>setNull</code> should be used for user-defined
1294: * types and REF type parameters. Examples of user-defined types include:
1295: * STRUCT, DISTINCT, JAVA_OBJECT, and named array types.
1296: * <P>
1297: * <B>Note:</B> To be portable, applications must give the SQL type code
1298: * and the fully-qualified SQL type name when specifying a NULL user-defined
1299: * or REF parameter. In the case of a user-defined type the name is the type
1300: * name of the parameter itself. For a REF parameter, the name is the type
1301: * name of the referenced type. If a JDBC driver does not need the type code
1302: * or type name information, it may ignore it. Although it is intended for
1303: * user-defined and Ref parameters, this method may be used to set a null
1304: * parameter of any JDBC type. If the parameter does not have a user-defined
1305: * or REF type, the given typeName is ignored.
1306: * @param paramIndex the first parameter is 1, the second is 2, ...
1307: * @param sqlType a value from <code>java.sql.Types</code>
1308: * @param typeName the fully-qualified name of an SQL user-defined type;
1309: * ignored if the parameter is not a user-defined type or REF
1310: * @exception SQLException if a database access error occurs
1311: * @since 1.2
1312: */
1313: public void setNull(int paramIndex, int sqlType, String typeName)
1314: throws SQLException {
1315: checkIfValid();
1316: pstmt.setNull(paramIndex, sqlType, typeName);
1317: }
1318:
1319: /**
1320: * <p>
1321: * Sets the value of the designated parameter using the given object. The
1322: * second parameter must be of type <code>Object</code>; therefore, the
1323: * <code>java.lang</code> equivalent objects should be used for built-in
1324: * types.
1325: * <p>
1326: * The JDBC specification specifies a standard mapping from Java
1327: * <code>Object</code> types to SQL types. The given argument will be
1328: * converted to the corresponding SQL type before being sent to the
1329: * database.
1330: * <p>
1331: * Note that this method may be used to pass datatabase- specific abstract
1332: * data types, by using a driver-specific Java type. If the object is of a
1333: * class implementing the interface <code>SQLData</code>, the JDBC driver
1334: * should call the method <code>SQLData.writeSQL</code> to write it to the
1335: * SQL data stream. If, on the other hand, the object is of a class
1336: * implementing <code>Ref</code>, <code>Blob</code>, <code>Clob</code>,
1337: * <code>Struct</code>, or <code>Array</code>, the driver should pass
1338: * it to the database as a value of the corresponding SQL type.
1339: * <P>
1340: * This method throws an exception if there is an ambiguity, for example, if
1341: * the object is of a class implementing more than one of the interfaces
1342: * named above.
1343: * @param parameterIndex the first parameter is 1, the second is 2, ...
1344: * @param x the object containing the input parameter value
1345: * @exception SQLException if a database access error occurs or the type of
1346: * the given object is ambiguous
1347: */
1348: public void setObject(int parameterIndex, Object x)
1349: throws SQLException {
1350: checkIfValid();
1351: pstmt.setObject(parameterIndex, x);
1352: }
1353:
1354: /**
1355: * Sets the value of the designated parameter with the given object. This
1356: * method is like the method <code>setObject</code> above, except that it
1357: * assumes a scale of zero.
1358: * @param parameterIndex the first parameter is 1, the second is 2, ...
1359: * @param x the object containing the input parameter value
1360: * @param targetSqlType the SQL type (as defined in java.sql.Types) to be
1361: * sent to the database
1362: * @exception SQLException if a database access error occurs
1363: */
1364: public void setObject(int parameterIndex, Object x,
1365: int targetSqlType) throws SQLException {
1366: checkIfValid();
1367: pstmt.setObject(parameterIndex, x, targetSqlType);
1368: }
1369:
1370: /**
1371: * <p>
1372: * Sets the value of the designated parameter with the given object. The
1373: * second argument must be an object type; for integral values, the
1374: * <code>java.lang</code> equivalent objects should be used.
1375: * <p>
1376: * The given Java object will be converted to the given targetSqlType before
1377: * being sent to the database. If the object has a custom mapping (is of a
1378: * class implementing the interface <code>SQLData</code>), the JDBC
1379: * driver should call the method <code>SQLData.writeSQL</code> to write it
1380: * to the SQL data stream. If, on the other hand, the object is of a class
1381: * implementing <code>Ref</code>, <code>Blob</code>, <code>Clob</code>,
1382: * <code>Struct</code>, or <code>Array</code>, the driver should pass
1383: * it to the database as a value of the corresponding SQL type.
1384: * <p>
1385: * Note that this method may be used to pass database-specific abstract data
1386: * types.
1387: * @param parameterIndex the first parameter is 1, the second is 2, ...
1388: * @param x the object containing the input parameter value
1389: * @param targetSqlType the SQL type (as defined in java.sql.Types) to be
1390: * sent to the database. The scale argument may further qualify this
1391: * type.
1392: * @param scale for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types,
1393: * this is the number of digits after the decimal point. For all
1394: * other types, this value will be ignored.
1395: * @exception SQLException if a database access error occurs
1396: * @see Types
1397: */
1398: public void setObject(int parameterIndex, Object x,
1399: int targetSqlType, int scale) throws SQLException {
1400: checkIfValid();
1401: pstmt.setObject(parameterIndex, x, targetSqlType, scale);
1402: }
1403:
1404: /**
1405: * Sets the designated parameter to the given
1406: * <code>REF(<structured-type>)</code> value. The driver converts
1407: * this to an SQL <code>REF</code> value when it sends it to the database.
1408: * @param i the first parameter is 1, the second is 2, ...
1409: * @param x an SQL <code>REF</code> value
1410: * @exception SQLException if a database access error occurs
1411: * @since 1.2
1412: */
1413: public void setRef(int i, Ref x) throws SQLException {
1414: checkIfValid();
1415: pstmt.setRef(i, x);
1416: }
1417:
1418: /**
1419: * Sets the designated parameter to the given Java <code>short</code>
1420: * value. The driver converts this to an SQL <code>SMALLINT</code> value
1421: * when it sends it to the database.
1422: * @param parameterIndex the first parameter is 1, the second is 2, ...
1423: * @param x the parameter value
1424: * @exception SQLException if a database access error occurs
1425: */
1426: public void setShort(int parameterIndex, short x)
1427: throws SQLException {
1428: checkIfValid();
1429: pstmt.setShort(parameterIndex, x);
1430: }
1431:
1432: /**
1433: * Sets the designated parameter to the given Java <code>String</code>
1434: * value. The driver converts this to an SQL <code>VARCHAR</code> or
1435: * <code>LONGVARCHAR</code> value (depending on the argument's size
1436: * relative to the driver's limits on <code>VARCHAR</code> values) when it
1437: * sends it to the database.
1438: * @param parameterIndex the first parameter is 1, the second is 2, ...
1439: * @param x the parameter value
1440: * @exception SQLException if a database access error occurs
1441: */
1442: public void setString(int parameterIndex, String x)
1443: throws SQLException {
1444: checkIfValid();
1445: pstmt.setString(parameterIndex, x);
1446: }
1447:
1448: /**
1449: * Sets the designated parameter to the given <code>java.sql.Time</code>
1450: * value. The driver converts this to an SQL <code>TIME</code> value when
1451: * it sends it to the database.
1452: * @param parameterIndex the first parameter is 1, the second is 2, ...
1453: * @param x the parameter value
1454: * @exception SQLException if a database access error occurs
1455: */
1456: public void setTime(int parameterIndex, Time x) throws SQLException {
1457: checkIfValid();
1458: pstmt.setTime(parameterIndex, x);
1459: }
1460:
1461: /**
1462: * Sets the designated parameter to the given <code>java.sql.Time</code>
1463: * value, using the given <code>Calendar</code> object. The driver uses
1464: * the <code>Calendar</code> object to construct an SQL <code>TIME</code>
1465: * value, which the driver then sends to the database. With a
1466: * <code>Calendar</code> object, the driver can calculate the time taking
1467: * into account a custom timezone. If no <code>Calendar</code> object is
1468: * specified, the driver uses the default timezone, which is that of the
1469: * virtual machine running the application.
1470: * @param parameterIndex the first parameter is 1, the second is 2, ...
1471: * @param x the parameter value
1472: * @param cal the <code>Calendar</code> object the driver will use to
1473: * construct the time
1474: * @exception SQLException if a database access error occurs
1475: * @since 1.2
1476: */
1477: public void setTime(int parameterIndex, Time x, Calendar cal)
1478: throws SQLException {
1479: checkIfValid();
1480: pstmt.setTime(parameterIndex, x, cal);
1481: }
1482:
1483: /**
1484: * Sets the designated parameter to the given
1485: * <code>java.sql.Timestamp</code> value. The driver converts this to an
1486: * SQL <code>TIMESTAMP</code> value when it sends it to the database.
1487: * @param parameterIndex the first parameter is 1, the second is 2, ...
1488: * @param x the parameter value
1489: * @exception SQLException if a database access error occurs
1490: */
1491: public void setTimestamp(int parameterIndex, Timestamp x)
1492: throws SQLException {
1493: checkIfValid();
1494: pstmt.setTimestamp(parameterIndex, x);
1495: }
1496:
1497: /**
1498: * Sets the designated parameter to the given
1499: * <code>java.sql.Timestamp</code> value, using the given
1500: * <code>Calendar</code> object. The driver uses the <code>Calendar</code>
1501: * object to construct an SQL <code>TIMESTAMP</code> value, which the
1502: * driver then sends to the database. With a <code>Calendar</code> object,
1503: * the driver can calculate the timestamp taking into account a custom
1504: * timezone. If no <code>Calendar</code> object is specified, the driver
1505: * uses the default timezone, which is that of the virtual machine running
1506: * the application.
1507: * @param parameterIndex the first parameter is 1, the second is 2, ...
1508: * @param x the parameter value
1509: * @param cal the <code>Calendar</code> object the driver will use to
1510: * construct the timestamp
1511: * @exception SQLException if a database access error occurs
1512: * @since 1.2
1513: */
1514: public void setTimestamp(int parameterIndex, Timestamp x,
1515: Calendar cal) throws SQLException {
1516: checkIfValid();
1517: pstmt.setTimestamp(parameterIndex, x, cal);
1518: }
1519:
1520: /**
1521: * Sets the designated parameter to the given input stream, which will have
1522: * the specified number of bytes. A Unicode character has two bytes, with
1523: * the first byte being the high byte, and the second being the low byte.
1524: * When a very large Unicode value is input to a <code>LONGVARCHAR</code>
1525: * parameter, it may be more practical to send it via a
1526: * <code>java.io.InputStream</code> object. The data will be read from the
1527: * stream as needed until end-of-file is reached. The JDBC driver will do
1528: * any necessary conversion from Unicode to the database char format.
1529: * <P>
1530: * <B>Note:</B> This stream object can either be a standard Java stream
1531: * object or your own subclass that implements the standard interface.
1532: * @param parameterIndex the first parameter is 1, the second is 2, ...
1533: * @param x a <code>java.io.InputStream</code> object that contains the
1534: * Unicode parameter value as two-byte Unicode characters
1535: * @param length the number of bytes in the stream
1536: * @exception SQLException if a database access error occurs
1537: * @deprecated
1538: */
1539: public void setUnicodeStream(int parameterIndex, InputStream x,
1540: int length) throws SQLException {
1541: checkIfValid();
1542: pstmt.setUnicodeStream(parameterIndex, x, length);
1543: }
1544:
1545: // Statement interface
1546:
1547: /**
1548: * Adds the given SQL command to the current list of commmands for this
1549: * <code>Statement</code> object. The commands in this list can be
1550: * executed as a batch by calling the method <code>executeBatch</code>.
1551: * <P>
1552: * <B>NOTE:</B> This method is optional.
1553: * @param s typically this is a static SQL <code>INSERT</code> or
1554: * <code>UPDATE</code> statement
1555: * @exception SQLException if a database access error occurs, or the driver
1556: * does not support batch updates
1557: * @see #executeBatch
1558: * @since 1.2
1559: */
1560: public void addBatch(String s) throws SQLException {
1561: checkIfValid();
1562: pstmt.addBatch(s);
1563: }
1564:
1565: /**
1566: * Cancels this <code>Statement</code> object if both the DBMS and driver
1567: * support aborting an SQL statement. This method can be used by one thread
1568: * to cancel a statement that is being executed by another thread.
1569: * @exception SQLException if a database access error occurs
1570: */
1571: public void cancel() throws SQLException {
1572: checkIfValid();
1573: pstmt.cancel();
1574: }
1575:
1576: /**
1577: * Empties this <code>Statement</code> object's current list of SQL
1578: * commands.
1579: * <P>
1580: * <B>NOTE:</B> This method is optional.
1581: * @exception SQLException if a database access error occurs or the driver
1582: * does not support batch updates
1583: * @see #addBatch
1584: * @since 1.2
1585: */
1586: public void clearBatch() throws SQLException {
1587: checkIfValid();
1588: pstmt.clearBatch();
1589: }
1590:
1591: /**
1592: * Clears all the warnings reported on this <code>Statement</code> object.
1593: * After a call to this method, the method <code>getWarnings</code> will
1594: * return <code>null</code> until a new warning is reported for this
1595: * <code>Statement</code> object.
1596: * @exception SQLException if a database access error occurs
1597: */
1598: public void clearWarnings() throws SQLException {
1599: checkIfValid();
1600: pstmt.clearWarnings();
1601: }
1602:
1603: /**
1604: * Releases this <code>Statement</code> object's database and JDBC
1605: * resources immediately instead of waiting for this to happen when it is
1606: * automatically closed. It is generally good practice to release resources
1607: * as soon as you are finished with them to avoid tying up database
1608: * resources.
1609: * <P>
1610: * Calling the method <code>close</code> on a <code>Statement</code>
1611: * object that is already closed has no effect.
1612: * <P>
1613: * <B>Note:</B> A <code>Statement</code> object is automatically closed
1614: * when it is garbage collected. When a <code>Statement</code> object is
1615: * closed, its current <code>ResultSet</code> object, if one exists, is
1616: * also closed.
1617: * @exception SQLException if a database access error occurs
1618: */
1619: public void close() throws SQLException {
1620: if (isDebugLogging) {
1621: trace.log(BasicLevel.DEBUG, "" + this );
1622: }
1623: closed = true;
1624: }
1625:
1626: /**
1627: * Executes the given SQL statement, which may return multiple results. In
1628: * some (uncommon) situations, a single SQL statement may return multiple
1629: * result sets and/or update counts. Normally you can ignore this unless you
1630: * are (1) executing a stored procedure that you know may return multiple
1631: * results or (2) you are dynamically executing an unknown SQL string.
1632: * <P>
1633: * The <code>execute</code> method executes an SQL statement and indicates
1634: * the form of the first result. You must then use the methods
1635: * <code>getResultSet</code> or <code>getUpdateCount</code> to retrieve
1636: * the result, and <code>getMoreResults</code> to move to any subsequent
1637: * result(s).
1638: * @param s any SQL statement
1639: * @return <code>true</code> if the first result is a
1640: * <code>ResultSet</code> object; <code>false</code> if it is an
1641: * update count or there are no results
1642: * @exception SQLException if a database access error occurs
1643: * @see #getResultSet
1644: * @see #getUpdateCount
1645: * @see #getMoreResults
1646: */
1647: public boolean execute(String s) throws SQLException {
1648: checkIfValid();
1649: return pstmt.execute(s);
1650: }
1651:
1652: /**
1653: * Submits a batch of commands to the database for execution and if all
1654: * commands execute successfully, returns an array of update counts. The
1655: * <code>int</code> elements of the array that is returned are ordered to
1656: * correspond to the commands in the batch, which are ordered according to
1657: * the order in which they were added to the batch. The elements in the
1658: * array returned by the method <code>executeBatch</code> may be one of
1659: * the following:
1660: * <OL>
1661: * <LI>A number greater than or equal to zero -- indicates that the command
1662: * was processed successfully and is an update count giving the number of
1663: * rows in the database that were affected by the command's execution
1664: * <LI>A value of <code>SUCCESS_NO_INFO</code> -- indicates that the
1665: * command was processed successfully but that the number of rows affected
1666: * is unknown
1667: * <P>
1668: * If one of the commands in a batch update fails to execute properly, this
1669: * method throws a <code>BatchUpdateException</code>, and a JDBC driver
1670: * may or may not continue to process the remaining commands in the batch.
1671: * However, the driver's behavior must be consistent with a particular DBMS,
1672: * either always continuing to process commands or never continuing to
1673: * process commands. If the driver continues processing after a failure, the
1674: * array returned by the method
1675: * <code>BatchUpdateException.getUpdateCounts</code> will contain as many
1676: * elements as there are commands in the batch, and at least one of the
1677: * elements will be the following:
1678: * <P>
1679: * <LI>A value of <code>EXECUTE_FAILED</code> -- indicates that the
1680: * command failed to execute successfully and occurs only if a driver
1681: * continues to process commands after a command fails
1682: * </OL>
1683: * <P>
1684: * A driver is not required to implement this method. The possible
1685: * implementations and return values have been modified in the Java 2 SDK,
1686: * Standard Edition, version 1.3 to accommodate the option of continuing to
1687: * proccess commands in a batch update after a
1688: * <code>BatchUpdateException</code> obejct has been thrown.
1689: * @return an array of update counts containing one element for each command
1690: * in the batch. The elements of the array are ordered according to
1691: * the order in which commands were added to the batch.
1692: * @exception SQLException if a database access error occurs or the driver
1693: * does not support batch statements. Throws
1694: * {@link BatchUpdateException} (a subclass of
1695: * <code>SQLException</code>) if one of the commands sent to
1696: * the database fails to execute properly or attempts to return a
1697: * result set.
1698: * @since 1.3
1699: */
1700: public int[] executeBatch() throws SQLException {
1701: checkIfValid();
1702: return pstmt.executeBatch();
1703: }
1704:
1705: /**
1706: * Executes the given SQL statement, which returns a single
1707: * <code>ResultSet</code> object.
1708: * @param s an SQL statement to be sent to the database, typically a static
1709: * SQL <code>SELECT</code> statement
1710: * @return a <code>ResultSet</code> object that contains the data produced
1711: * by the given query; never <code>null</code>
1712: * @exception SQLException if a database access error occurs or the given
1713: * SQL statement produces anything other than a single
1714: * <code>ResultSet</code> object
1715: */
1716: public ResultSet executeQuery(String s) throws SQLException {
1717: checkIfValid();
1718: return pstmt.executeQuery(s);
1719: }
1720:
1721: /**
1722: * Executes the given SQL statement, which may be an <code>INSERT</code>,
1723: * <code>UPDATE</code>, or <code>DELETE</code> statement or an SQL
1724: * statement that returns nothing, such as an SQL DDL statement.
1725: * @param s an SQL <code>INSERT</code>, <code>UPDATE</code> or
1726: * <code>DELETE</code> statement or an SQL statement that returns
1727: * nothing
1728: * @return either the row count for <code>INSERT</code>,
1729: * <code>UPDATE</code> or <code>DELETE</code> statements, or
1730: * <code>0</code> for SQL statements that return nothing
1731: * @exception SQLException if a database access error occurs or the given
1732: * SQL statement produces a <code>ResultSet</code> object
1733: */
1734: public int executeUpdate(String s) throws SQLException {
1735: checkIfValid();
1736: return pstmt.executeUpdate(s);
1737: }
1738:
1739: /**
1740: * Retrieves the <code>Connection</code> object that produced this
1741: * <code>Statement</code> object.
1742: * @return the connection that produced this statement
1743: * @exception SQLException if a database access error occurs
1744: * @since 1.2
1745: */
1746: public Connection getConnection() throws SQLException {
1747: checkIfValid();
1748: return pstmt.getConnection();
1749: }
1750:
1751: /**
1752: * Retrieves the direction for fetching rows from database tables that is
1753: * the default for result sets generated from this <code>Statement</code>
1754: * object. If this <code>Statement</code> object has not set a fetch
1755: * direction by calling the method <code>setFetchDirection</code>, the
1756: * return value is implementation-specific.
1757: * @return the default fetch direction for result sets generated from this
1758: * <code>Statement</code> object
1759: * @exception SQLException if a database access error occurs
1760: * @since 1.2
1761: * @see #setFetchDirection
1762: */
1763: public int getFetchDirection() throws SQLException {
1764: checkIfValid();
1765: return pstmt.getFetchDirection();
1766: }
1767:
1768: /**
1769: * Retrieves the number of result set rows that is the default fetch size
1770: * for <code>ResultSet</code> objects generated from this
1771: * <code>Statement</code> object. If this <code>Statement</code> object
1772: * has not set a fetch size by calling the method <code>setFetchSize</code>,
1773: * the return value is implementation-specific.
1774: * @return the default fetch size for result sets generated from this
1775: * <code>Statement</code> object
1776: * @exception SQLException if a database access error occurs
1777: * @since 1.2
1778: * @see #setFetchSize
1779: */
1780: public int getFetchSize() throws SQLException {
1781: checkIfValid();
1782: return pstmt.getFetchSize();
1783: }
1784:
1785: /**
1786: * Retrieves the maximum number of bytes that can be returned for character
1787: * and binary column values in a <code>ResultSet</code> object produced by
1788: * this <code>Statement</code> object. This limit applies only to
1789: * <code>BINARY</code>, <code>VARBINARY</code>,
1790: * <code>LONGVARBINARY</code>, <code>CHAR</code>, <code>VARCHAR</code>,
1791: * and <code>LONGVARCHAR</code> columns. If the limit is exceeded, the
1792: * excess data is silently discarded.
1793: * @return the current column size limit for columns storing character and
1794: * binary values; zero means there is no limit
1795: * @exception SQLException if a database access error occurs
1796: * @see #setMaxFieldSize
1797: */
1798: public int getMaxFieldSize() throws SQLException {
1799: checkIfValid();
1800: return pstmt.getMaxFieldSize();
1801: }
1802:
1803: /**
1804: * Retrieves the maximum number of rows that a <code>ResultSet</code>
1805: * object produced by this <code>Statement</code> object can contain. If
1806: * this limit is exceeded, the excess rows are silently dropped.
1807: * @return the current maximum number of rows for a <code>ResultSet</code>
1808: * object produced by this <code>Statement</code> object; zero
1809: * means there is no limit
1810: * @exception SQLException if a database access error occurs
1811: * @see #setMaxRows
1812: */
1813: public int getMaxRows() throws SQLException {
1814: checkIfValid();
1815: return pstmt.getMaxRows();
1816: }
1817:
1818: /**
1819: * Moves to this <code>Statement</code> object's next result, returns
1820: * <code>true</code> if it is a <code>ResultSet</code> object, and
1821: * implicitly closes any current <code>ResultSet</code> object(s) obtained
1822: * with the method <code>getResultSet</code>.
1823: * <P>
1824: * There are no more results when the following is true:
1825: *
1826: * <PRE> // stmt is a Statement object ((stmt.getMoreResults() == false) &&
1827: * (stmt.getUpdateCount() == -1))
1828: *
1829: * </PRE>
1830: *
1831: * @return <code>true</code> if the next result is a
1832: * <code>ResultSet</code> object; <code>false</code> if it is an
1833: * update count or there are no more results
1834: * @exception SQLException if a database access error occurs
1835: * @see #execute
1836: */
1837: public boolean getMoreResults() throws SQLException {
1838: checkIfValid();
1839: return pstmt.getMoreResults();
1840: }
1841:
1842: /**
1843: * Retrieves the number of seconds the driver will wait for a
1844: * <code>Statement</code> object to execute. If the limit is exceeded, a
1845: * <code>SQLException</code> is thrown.
1846: * @return the current query timeout limit in seconds; zero means there is
1847: * no limit
1848: * @exception SQLException if a database access error occurs
1849: * @see #setQueryTimeout
1850: */
1851: public int getQueryTimeout() throws SQLException {
1852: checkIfValid();
1853: return pstmt.getQueryTimeout();
1854: }
1855:
1856: /**
1857: * Retrieves the current result as a <code>ResultSet</code> object. This
1858: * method should be called only once per result.
1859: * @return the current result as a <code>ResultSet</code> object or
1860: * <code>null</code> if the result is an update count or there are
1861: * no more results
1862: * @exception SQLException if a database access error occurs
1863: * @see #execute
1864: */
1865: public ResultSet getResultSet() throws SQLException {
1866: checkIfValid();
1867: return pstmt.getResultSet();
1868: }
1869:
1870: /**
1871: * Retrieves the result set concurrency for <code>ResultSet</code> objects
1872: * generated by this <code>Statement</code> object.
1873: * @return either <code>ResultSet.CONCUR_READ_ONLY</code> or
1874: * <code>ResultSet.CONCUR_UPDATABLE</code>
1875: * @exception SQLException if a database access error occurs
1876: * @since 1.2
1877: */
1878: public int getResultSetConcurrency() throws SQLException {
1879: checkIfValid();
1880: return pstmt.getResultSetConcurrency();
1881: }
1882:
1883: /**
1884: * Retrieves the result set type for <code>ResultSet</code> objects
1885: * generated by this <code>Statement</code> object.
1886: * @return one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
1887: * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
1888: * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
1889: * @exception SQLException if a database access error occurs
1890: * @since 1.2
1891: */
1892: public int getResultSetType() throws SQLException {
1893: checkIfValid();
1894: return pstmt.getResultSetType();
1895: }
1896:
1897: /**
1898: * Retrieves the current result as an update count; if the result is a
1899: * <code>ResultSet</code> object or there are no more results, -1 is
1900: * returned. This method should be called only once per result.
1901: * @return the current result as an update count; -1 if the current result
1902: * is a <code>ResultSet</code> object or there are no more results
1903: * @exception SQLException if a database access error occurs
1904: * @see #execute
1905: */
1906: public int getUpdateCount() throws SQLException {
1907: checkIfValid();
1908: return pstmt.getUpdateCount();
1909: }
1910:
1911: /**
1912: * Retrieves the first warning reported by calls on this
1913: * <code>Statement</code> object. Subsequent <code>Statement</code>
1914: * object warnings will be chained to this <code>SQLWarning</code> object.
1915: * <p>
1916: * The warning chain is automatically cleared each time a statement is
1917: * (re)executed. This method may not be called on a closed
1918: * <code>Statement</code> object; doing so will cause an
1919: * <code>SQLException</code> to be thrown.
1920: * <P>
1921: * <B>Note:</B> If you are processing a <code>ResultSet</code> object,
1922: * any warnings associated with reads on that <code>ResultSet</code>
1923: * object will be chained on it rather than on the <code>Statement</code>
1924: * object that produced it.
1925: * @return the first <code>SQLWarning</code> object or <code>null</code>
1926: * if there are no warnings
1927: * @exception SQLException if a database access error occurs or this method
1928: * is called on a closed statement
1929: */
1930: public SQLWarning getWarnings() throws SQLException {
1931: checkIfValid();
1932: return pstmt.getWarnings();
1933: }
1934:
1935: /**
1936: * Sets the SQL cursor name to the given <code>String</code>, which will
1937: * be used by subsequent <code>Statement</code> object
1938: * <code>execute</code> methods. This name can then be used in SQL
1939: * positioned update or delete statements to identify the current row in the
1940: * <code>ResultSet</code> object generated by this statement. If the
1941: * database does not support positioned update/delete, this method is a
1942: * noop. To insure that a cursor has the proper isolation level to support
1943: * updates, the cursor's <code>SELECT</code> statement should have the
1944: * form <code>SELECT FOR UPDATE</code>. If <code>FOR UPDATE</code> is
1945: * not present, positioned updates may fail.
1946: * <P>
1947: * <B>Note:</B> By definition, the execution of positioned updates and
1948: * deletes must be done by a different <code>Statement</code> object than
1949: * the one that generated the <code>ResultSet</code> object being used for
1950: * positioning. Also, cursor names must be unique within a connection.
1951: * @param name the new cursor name, which must be unique within a connection
1952: * @exception SQLException if a database access error occurs
1953: */
1954: public void setCursorName(String name) throws SQLException {
1955: checkIfValid();
1956: pstmt.setCursorName(name);
1957: }
1958:
1959: /**
1960: * Sets escape processing on or off. If escape scanning is on (the default),
1961: * the driver will do escape substitution before sending the SQL statement
1962: * to the database. Note: Since prepared statements have usually been parsed
1963: * prior to making this call, disabling escape processing for
1964: * <code>PreparedStatements</code> objects will have no effect.
1965: * @param enable <code>true</code> to enable escape processing;
1966: * <code>false</code> to disable it
1967: * @exception SQLException if a database access error occurs
1968: */
1969: public void setEscapeProcessing(boolean enable) throws SQLException {
1970: checkIfValid();
1971: // mark this method as called (even if it doesn't succeed)
1972: setEscapeProcessingCalled = true;
1973: pstmt.setEscapeProcessing(enable);
1974: }
1975:
1976: /**
1977: * Gives the driver a hint as to the direction in which rows will be
1978: * processed in <code>ResultSet</code> objects created using this
1979: * <code>Statement</code> object. The default value is
1980: * <code>ResultSet.FETCH_FORWARD</code>.
1981: * <P>
1982: * Note that this method sets the default fetch direction for result sets
1983: * generated by this <code>Statement</code> object. Each result set has
1984: * its own methods for getting and setting its own fetch direction.
1985: * @param direction the initial direction for processing rows
1986: * @exception SQLException if a database access error occurs or the given
1987: * direction is not one of <code>ResultSet.FETCH_FORWARD</code>,
1988: * <code>ResultSet.FETCH_REVERSE</code>, or
1989: * <code>ResultSet.FETCH_UNKNOWN</code>
1990: * @since 1.2
1991: * @see #getFetchDirection
1992: */
1993: public void setFetchDirection(int direction) throws SQLException {
1994: checkIfValid();
1995: // mark this method as called (even if it doesn't succeed)
1996: setFetchDirectionCalled = true;
1997: pstmt.setFetchDirection(direction);
1998: }
1999:
2000: /**
2001: * Gives the JDBC driver a hint as to the number of rows that should be
2002: * fetched from the database when more rows are needed. The number of rows
2003: * specified affects only result sets created using this statement. If the
2004: * value specified is zero, then the hint is ignored. The default value is
2005: * zero.
2006: * @param rows the number of rows to fetch
2007: * @exception SQLException if a database access error occurs, or the
2008: * condition 0 <= <code>rows</code> <=
2009: * <code>this.getMaxRows()</code> is not satisfied.
2010: * @since 1.2
2011: * @see #getFetchSize
2012: */
2013: public void setFetchSize(int rows) throws SQLException {
2014: checkIfValid();
2015: pstmt.setFetchSize(rows);
2016: }
2017:
2018: /**
2019: * Sets the limit for the maximum number of bytes in a
2020: * <code>ResultSet</code> column storing character or binary values to the
2021: * given number of bytes. This limit applies only to <code>BINARY</code>,
2022: * <code>VARBINARY</code>, <code>LONGVARBINARY</code>,
2023: * <code>CHAR</code>, <code>VARCHAR</code>, and
2024: * <code>LONGVARCHAR</code> fields. If the limit is exceeded, the excess
2025: * data is silently discarded. For maximum portability, use values greater
2026: * than 256.
2027: * @param max the new column size limit in bytes; zero means there is no
2028: * limit
2029: * @exception SQLException if a database access error occurs or the
2030: * condition max >= 0 is not satisfied
2031: * @see #getMaxFieldSize
2032: */
2033: public void setMaxFieldSize(int max) throws SQLException {
2034: checkIfValid();
2035: // mark this method as called (even if it doesn't succeed)
2036: setMaxFieldSizeCalled = true;
2037: pstmt.setMaxFieldSize(max);
2038: }
2039:
2040: /**
2041: * Sets the limit for the maximum number of rows that any
2042: * <code>ResultSet</code> object can contain to the given number. If the
2043: * limit is exceeded, the excess rows are silently dropped.
2044: * @param max the new max rows limit; zero means there is no limit
2045: * @exception SQLException if a database access error occurs or the
2046: * condition max >= 0 is not satisfied
2047: * @see #getMaxRows
2048: */
2049: public void setMaxRows(int max) throws SQLException {
2050: checkIfValid();
2051: pstmt.setMaxRows(max);
2052: }
2053:
2054: /**
2055: * Sets the number of seconds the driver will wait for a
2056: * <code>Statement</code> object to execute to the given number of
2057: * seconds. If the limit is exceeded, an <code>SQLException</code> is
2058: * thrown.
2059: * @param seconds the new query timeout limit in seconds; zero means there
2060: * is no limit
2061: * @exception SQLException if a database access error occurs or the
2062: * condition seconds >= 0 is not satisfied
2063: * @see #getQueryTimeout
2064: */
2065: public void setQueryTimeout(int seconds) throws SQLException {
2066: checkIfValid();
2067: pstmt.setQueryTimeout(seconds);
2068: }
2069:
2070: // JDK1.4
2071: /**
2072: * Sets the designated parameter to the given <code>java.net.URL</code>
2073: * value. The driver converts this to an SQL <code>DATALINK</code> value
2074: * when it sends it to the database.
2075: * @param parameterIndex the first parameter is 1, the second is 2, ...
2076: * @param x the <code>java.net.URL</code> object to be set
2077: * @exception SQLException if a database access error occurs
2078: * @since 1.4
2079: */
2080: public void setURL(int parameterIndex, URL x) throws SQLException {
2081: checkIfValid();
2082: pstmt.setURL(parameterIndex, x);
2083: }
2084:
2085: /**
2086: * @return hashcode of the object
2087: */
2088: public int hashCode() {
2089: return hashCode;
2090: }
2091:
2092: /**
2093: * @return true if statement has been closed
2094: */
2095: public boolean isClosed() {
2096: return closed;
2097: }
2098:
2099: }
|