Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * $Id: AbstractPreparedStatement.java 58744 2013-11-02 11:59:48Z mrotteveel $
    * 
    * Firebird Open Source J2ee connector - jdbc driver
    *
    * Distributable under LGPL license.
    * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html
    *
    * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * LGPL License for more details.
   *
   * This file was created by members of the firebird development team.
   * All individual contributions remain the Copyright (C) of those
   * individuals.  Contributors to this file are either listed here or
   * can be obtained from a CVS history command.
   *
   * All rights reserved.
   */
  package org.firebirdsql.jdbc;
  
  import java.io.*;
  import java.math.*;
  import java.net.URL;
  import java.sql.*;
  import java.sql.Date;
  import java.util.*;
  
Implementation of java.sql.PreparedStatementinterface. This class contains all methods from the JDBC 2.0 specification.

Author(s):
David Jencks
Roman Rokytskyy
Mark Rotteveel
  
  public abstract class AbstractPreparedStatement extends AbstractStatement implements
          FirebirdPreparedStatement {
      
      static final String METHOD_NOT_SUPPORTED = "This method is only supported on Statement and not supported on PreparedStatement and CallableStatement";
  
      private boolean metaDataQuery;

    
This flag is needed to guarantee the correct behavior in case when it was created without controlling Connection object (in some metadata queries we have only GDSHelper instance)
  
      private boolean standaloneStatement;

    
This flag is needed to prevent throwing an exception for the case when result set is returned for INSERT statement and the statement should return the generated keys.
  
      private boolean generatedKeys;
  
      // this array contains either true or false indicating if parameter
      // was initialized, executeQuery, executeUpdate and execute methods
      // will throw an exception if this array contains at least one false value.
      protected boolean[] isParamSet;
  
      private FBField[] fields = null;
  
      // we need to handle procedure execution separately,
      // because in this case we must send out_xsqlda to the server.
      private boolean isExecuteProcedureStatement;
  
      private boolean trimStrings;
  
      private FBObjectListener.BlobListener blobListener;

    
Create instance of this class for the specified result set type and concurrency. This constructor is used only in AbstractCallableStatement since the statement is prepared right before the execution.

Parameters:
c instance of org.firebirdsql.gds.impl.GDSHelper that will be used to perform all database activities.
rsType desired result set type.
rsConcurrency desired result set concurrency.
statementListener statement listener that will be notified about the statement start, close and completion.
Throws:
java.sql.SQLException if something went wrong.
  
      protected AbstractPreparedStatement(GDSHelper cint rsType,
              int rsConcurrencyint rsHoldability,
              FBObjectListener.StatementListener statementListener,
              FBObjectListener.BlobListener blobListener)
              throws SQLException {
 
         super(crsTypersConcurrencyrsHoldabilitystatementListener);
         this. = blobListener;
     }

    
Create instance of this class and prepare SQL statement.

Parameters:
c connection to be used.
sql SQL statement to prepare.
rsType type of result set to create.
rsConcurrency result set concurrency.
Throws:
java.sql.SQLException if something went wrong.
 
     protected AbstractPreparedStatement(GDSHelper cString sqlint rsType,
             int rsConcurrencyint rsHoldability,
             FBObjectListener.StatementListener statementListener,
             FBObjectListener.BlobListener blobListener,
             boolean metaDataQueryboolean standaloneStatementboolean generatedKeys)
             throws SQLException {
         super(crsTypersConcurrencyrsHoldabilitystatementListener);
 
         this. = blobListener;
         this. = metaDataQuery;
         this. = standaloneStatement;
         this. = generatedKeys;
 
         try {
             notifyStatementStarted();
             prepareFixedStatement(sqltrue);
         } catch (GDSException ge) {
             notifyStatementCompleted(false);
             throw new FBSQLException(ge);
         } catch (SQLException sqle) {
             notifyStatementCompleted(false);
             throw sqle;
         } catch (RuntimeException e) {
             notifyStatementCompleted(false);
             throw e;
         }
     }
     
     @Override
     public void completeStatement(CompletionReason reasonthrows SQLException {
         if (!) {
             super.completeStatement(reason);
         } else if (!) {
             notifyStatementCompleted();
         }
     }
     
     protected void notifyStatementCompleted(boolean success)
             throws SQLException {
         try {
             super.notifyStatementCompleted(success);
         } finally {
             if ( && )
                 close();
         }
     }

    
Executes the SQL query in this PreparedStatement object and returns the result set generated by the query.

Returns:
a ResultSet object that contains the data produced by the query; never null
Throws:
java.sql.SQLException if a database access error occurs
 
     public ResultSet executeQuery() throws SQLException {
 
         Object syncObject = getSynchronizationObject();
         synchronized (syncObject) {
             notifyStatementStarted();
 
             if (!internalExecute())
                 throw new FBSQLException(
                     "No resultset for sql",
                     .);
 
             return getResultSet();
         }
     }

    
Executes the SQL INSERT, UPDATE or DELETE statement in this PreparedStatement object. In addition, SQL statements that return nothing, such as SQL DDL statements, can be executed.

Returns:
either the row count for INSERT, UPDATE or DELETE statements; or 0 for SQL statements that return nothing
Throws:
java.sql.SQLException if a database access error occurs
 
     public int executeUpdate() throws SQLException {
 
         Object syncObject = getSynchronizationObject();
         synchronized (syncObject) {
             notifyStatementStarted();
             try {
                 if (internalExecute() && !) {
                     throw new FBSQLException(
                             "Update statement returned results.");
                 }
 
                 return getUpdateCount();
             } finally {
                 notifyStatementCompleted();
             }
         }
     }
 
         return new FBParameterMetaData(.getInSqlda().);
     }

    
Sets the designated parameter to SQL NULL.

Note: You must specify the parameter's SQL type.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
sqlType the SQL type code defined in java.sql.Types
Throws:
java.sql.SQLException if a database access error occurs
 
     public void setNull(int parameterIndexint sqlTypethrows SQLException {
         getField(parameterIndex).setNull();
         [parameterIndex - 1] = true;
     }

    
Sets the designated parameter to the given input stream, which will have the specified number of bytes.

Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
inputStream the Java input stream
length the number of bytes in the stream
Throws:
java.sql.SQLException if a database access error occurs
 
     public void setBinaryStream(int parameterIndexInputStream inputStream,
             int lengththrows SQLException {
         getField(parameterIndex).setBinaryStream(inputStreamlength);
         [parameterIndex - 1] = true;
     }
     
     public void setBinaryStream(int parameterIndexInputStream xlong length)
             throws SQLException {
         if (length > .)
             throw new FBDriverNotCapableException("Only length <= Integer.MAX_VALUE supported");
         setBinaryStream(parameterIndexx, (int)length);
     }
 
     public void setBinaryStream(int parameterIndexInputStream x)
             throws SQLException {
         throw new FBDriverNotCapableException();
     }

    
Set the designated parameter to the given byte array.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x The byte array to be set
Throws:
java.sql.SQLException if a database access occurs
 
     public void setBytes(int parameterIndexbyte[] xthrows SQLException {
         getField(parameterIndex).setBytes(x);
         [parameterIndex - 1] = true;
     }

    
Sets the designated parameter to the given boolean value.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x The boolean value to be set
Throws:
java.sql.SQLException if a database access occurs
 
     public void setBoolean(int parameterIndexboolean xthrows SQLException {
         getField(parameterIndex).setBoolean(x);
         [parameterIndex - 1] = true;
     }

    
Sets the designated parameter to the given byte value.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x The byte value to be set
Throws:
java.sql.SQLException if a database access occurs
 
     public void setByte(int parameterIndexbyte xthrows SQLException {
         getField(parameterIndex).setByte(x);
         [parameterIndex - 1] = true;
     }

    
Sets the designated parameter to the given date value.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x The date value to be set
Throws:
java.sql.SQLException if a database access occurs
 
     public void setDate(int parameterIndexDate xthrows SQLException {
         getField(parameterIndex).setDate(x);
         [parameterIndex - 1] = true;
     }

    
Sets the designated parameter to the given double value.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x The double value to be set
Throws:
java.sql.SQLException if a database access occurs
 
     public void setDouble(int parameterIndexdouble xthrows SQLException {
         getField(parameterIndex).setDouble(x);
         [parameterIndex - 1] = true;
     }

    
Sets the designated parameter to the given floate value.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x The float value to be set
Throws:
java.sql.SQLException if a database access occurs
 
     public void setFloat(int parameterIndexfloat xthrows SQLException {
         getField(parameterIndex).setFloat(x);
         [parameterIndex - 1] = true;
     }

    
Sets the designated parameter to the given int value.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x The int value to be set
Throws:
java.sql.SQLException if a database access occurs
 
     public void setInt(int parameterIndexint xthrows SQLException {
         getField(parameterIndex).setInteger(x);
         [parameterIndex - 1] = true;
     }

    
Sets the designated parameter to the given long value.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x The long value to be set
Throws:
java.sql.SQLException if a database access occurs
 
     public void setLong(int parameterIndexlong xthrows SQLException {
         getField(parameterIndex).setLong(x);
         [parameterIndex - 1] = true;
     }

    
Sets the value of the designated parameter with the given object.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x the object containing the parameter value
Throws:
java.sql.SQLException if a database access error occurs
 
     public void setObject(int parameterIndexObject xthrows SQLException {
         getField(parameterIndex).setObject(x);
         [parameterIndex - 1] = true;
     }

    
Sets the designated parameter to the given short value.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x The short value to be set
Throws:
java.sql.SQLException if a database access occurs
 
     public void setShort(int parameterIndexshort xthrows SQLException {
         getField(parameterIndex).setShort(x);
         [parameterIndex - 1] = true;
     }

    
Sets the designated parameter to the given String value.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x The String value to be set
Throws:
java.sql.SQLException if a database access occurs
 
     public void setString(int parameterIndexString xthrows SQLException {
         getField(parameterIndex).setString(x);
         [parameterIndex - 1] = true;
     }

    
Sets the designated parameter to the given String value. This is a workaround for the ambiguous "operation was cancelled" response from the server for when an oversized string is set for a limited-size field. This method sets the string parameter without checking size constraints.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x The String value to be set
Throws:
java.sql.SQLException if a database access occurs
 
     public void setStringForced(int parameterIndexString x)
             throws SQLException {
         FBField field = getField(parameterIndex);
         if (field instanceof FBWorkaroundStringField)
             ((FBWorkaroundStringFieldfield).setStringForced(x);
         else
             field.setString(x);
         [parameterIndex - 1] = true;
     }

    
Sets the designated parameter to the given Time value.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x The Time value to be set
Throws:
java.sql.SQLException if a database access occurs
 
     public void setTime(int parameterIndexTime xthrows SQLException {
         getField(parameterIndex).setTime(x);
         [parameterIndex - 1] = true;
     }

    
Sets the designated parameter to the given Timestamp value.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x The Timestamp value to be set
Throws:
java.sql.SQLException if a database access occurs
 
     public void setTimestamp(int parameterIndexTimestamp x)
             throws SQLException {
         getField(parameterIndex).setTimestamp(x);
         [parameterIndex - 1] = true;
     }

    
Sets the designated parameter to the given BigDecimal

Parameters:
parameterIndex The first parameter is 1, second is 2, ...
x The BigDecimal to be set as a parameter
Throws:
java.sql.SQLException if a database access error occurs
 
     public void setBigDecimal(int parameterIndexBigDecimal x)
             throws SQLException {
         getField(parameterIndex).setBigDecimal(x);
         [parameterIndex - 1] = true;
     }

    
Returns the XSQLVAR structure for the specified column.
 
     protected XSQLVAR getXsqlvar(int columnIndex) {
         return .getInSqlda().[columnIndex - 1];
     }

    
Factory method for the field access objects
 
     protected FBField getField(int columnIndexthrows SQLException {
         if (columnIndex > .)
             throw new FBSQLException("Invalid column index.",
                     .);
 
         return [columnIndex - 1];
     }

    
Sets the designated parameter to the given input stream, which will have the specified number of bytes. When a very large ASCII value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.InputStream. Data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from ASCII to the database char format.

Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x the Java input stream that contains the ASCII parameter value
length the number of bytes in the stream
Throws:
java.sql.SQLException if a database access error occurs
 
     public void setAsciiStream(int parameterIndexInputStream xint length)
             throws SQLException {
         setBinaryStream(parameterIndexxlength);
     }
     
     public void setAsciiStream(int parameterIndexInputStream xlong length)
             throws SQLException {
         setBinaryStream(parameterIndexxlength);
     }
 
     public void setAsciiStream(int parameterIndexInputStream x)
             throws SQLException {
         setBinaryStream(parameterIndexx);
     }

    
Sets the designated parameter to the given input stream, which will have the specified number of bytes. When a very large UNICODE value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.InputStream object. The data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from UNICODE to the database char format. The byte format of the Unicode stream must be Java UTF-8, as defined in the Java Virtual Machine Specification.

Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.

Deprecated:
I really have no idea if there is anything else we should be doing here
Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x the java input stream which contains the UNICODE parameter value
length the number of bytes in the stream
Throws:
java.sql.SQLException if a database access error occurs
 
     public void setUnicodeStream(int parameterIndexInputStream xint length)
             throws SQLException {
         setBinaryStream(parameterIndexxlength);
         [parameterIndex - 1] = true;
     }
     
     public void setURL(int parameterIndexURL urlthrows SQLException {
         throw new FBDriverNotCapableException();
     }
     
     public void setNCharacterStream(int parameterIndexReader value,
             long lengththrows SQLException {
         throw new FBDriverNotCapableException();
     }
 
     public void setNCharacterStream(int parameterIndexReader value)
             throws SQLException {
         throw new FBDriverNotCapableException();
     }
 
     public void setNClob(int parameterIndexReader readerlong length)
             throws SQLException {
         throw new FBDriverNotCapableException();
     }
 
     public void setNClob(int parameterIndexReader readerthrows SQLException {
         throw new FBDriverNotCapableException();
     }
 
     public void setNString(int parameterIndexString value)
             throws SQLException {
         throw new FBDriverNotCapableException();
     }

    
Clears the current parameter values immediately.

In general, parameter values remain in force for repeated use of a statement. Setting a parameter value automatically clears its previous value. However, in some cases it is useful to immediately release the resources used by the current parameter values; this can be done by calling the method clearParameters.

Throws:
java.sql.SQLException if a database access error occurs
 
     public void clearParameters() throws SQLException {
         if ( == nullreturn;
 
         for (int i = 0; i < .i++)
             [i] = false;
 
         XSQLVAR[] xsqlvar = .getInSqlda().;
         for (int i = 0; i < xsqlvar.lengthi++) {
             xsqlvar[i]. = null;
         }
     }
 
     // ----------------------------------------------------------------------
     // Advanced features:
 
    

Sets the value of the designated parameter with the given object. The second argument must be an object type; for integral values, the java.lang equivalent objects should be used.

The given Java object will be converted to the given targetSqlType before being sent to the database. If the object has a custom mapping (is of a class implementing the interface SQLData), the JDBC driver should call the method SQLData.writeSQL to write it to the SQL data stream. If, on the other hand, the object is of a class implementing Ref, Blob, Clob, Struct, or Array, the driver should pass it to the database as a value of the corresponding SQL type.

Note that this method may be used to pass datatabase- specific abstract data types.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x the object containing the input parameter value
targetSqlType the SQL type (as defined in java.sql.Types) to be sent to the database. The scale argument may further qualify this type.
scale for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types, this is the number of digits after the decimal point. For all other types, this value will be ignored.
Throws:
java.sql.SQLException if a database access error occurs
See also:
java.sql.Types
 
     public void setObject(int parameterIndexObject xint targetSqlType,
             int scalethrows SQLException {
         // Workaround for JBuilder DataSets
         setObject(parameterIndexx);
         [parameterIndex - 1] = true;
     }

    
Sets the value of the designated parameter with the given object. This method is like the method setObject above, except that it assumes a scale of zero.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x the object containing the input parameter value
targetSqlType the SQL type (as defined in java.sql.Types) to be sent to the database
Throws:
java.sql.SQLException if a database access error occurs
 
     public void setObject(int parameterIndexObject xint targetSqlType)
             throws SQLException {
         // well, for now
         setObject(parameterIndexx);
         [parameterIndex - 1] = true;
     }

    
Executes any kind of SQL statement. Some prepared statements return multiple results; the execute method handles these complex statements as well as the simpler form of statements handled by the methods executeQuery and executeUpdate.

Throws:
java.sql.SQLException if a database access error occurs
See also:
java.sql.Statement.execute(java.lang.String)
 
     public boolean execute() throws SQLException {
 
         Object syncObject = getSynchronizationObject();
         synchronized (syncObject) {
             notifyStatementStarted();
 
             boolean hasResultSet = internalExecute();
 
             if (!hasResultSet)
                 notifyStatementCompleted();
 
             return hasResultSet;
         }
     }

    
Execute meta-data query. This method is similar to executeQuery()however, it always returns cached result set and strings in the result set are always trimmed (server defines system tables using CHAR data type, but it should be used as VARCHAR).

Returns:
result set corresponding to the specified query.
Throws:
java.sql.SQLException if something went wrong or no result set was available.
 
 
         Object syncObject = getSynchronizationObject();
         synchronized (syncObject) {
             notifyStatementStarted();
 
             boolean hasResultSet = internalExecute();
 
             if (!hasResultSet)
                 throw new FBSQLException("No result set is available.");
 
             return getResultSet(true);
         }
     }

    
Execute this statement. Method checks whether all parameters are set, flushes all "flushable" fields that might contain cached data and executes the statement.

Parameters:
sendOutParams
Returns:
true if the statement has more result sets.
Throws:
java.sql.SQLException
 
     protected boolean internalExecute(boolean sendOutParams)
             throws SQLException {
 
         boolean canExecute = true;
         for (int i = 0; i < .i++) {
             canExecute = canExecute && [i];
         }
 
         if (!canExecute)
             throw new FBMissingParameterException(
                     "Not all parameters were set.");
 
         Object syncObject = getSynchronizationObject();
 
         synchronized (syncObject) {
 
             flushFields();
 
             try {
                 .executeStatement(sendOutParams);
                  = (.getOutSqlda(). > 0);
                 return (.getOutSqlda(). > 0);
             } catch (GDSException ge) {
                 throw new FBSQLException(ge);
             } finally {
                  = true;
             }
         }
     }

    
Flush fields that might have cached data.

Throws:
java.sql.SQLException if something went wrong.
 
     private void flushFields() throws SQLException {
         // flush any cached data that can be hanging
         for (int i = 0; i < .i++) {
             FBField field = getField(i + 1);
 
             if (!(field instanceof FBFlushableField)) continue;
 
             ((FBFlushableFieldfield).flushCachedData();
         }
     }
 
     protected final List batchList = new LinkedList();

    
Adds a set of parameters to this PreparedStatement object's batch of commands.

Throws:
java.sql.SQLException if a database access error occurs
Since:
1.2
See also:
java.sql.Statement.addBatch(java.lang.String)
What Is in the JDBC 2.0 API
 
     public void addBatch() throws SQLException {
 
         boolean allParamsSet = true;
         for (int i = 0; i < .i++) {
             allParamsSet &= [i];
         }
 
         if (!allParamsSetthrow new FBSQLException("Not all parameters set.");
 
         XSQLVAR[] oldXsqlvar = .getInSqlda().;
 
         XSQLVAR[] newXsqlvar = new XSQLVAR[oldXsqlvar.length];
         for (int i = 0; i < newXsqlvar.lengthi++) {
             newXsqlvar[i] = oldXsqlvar[i].deepCopy();
 
             FBField field = getField(i + 1);
             if (field instanceof FBFlushableField)
                 newXsqlvar[i]. = ((FBFlushableField)field).getCachedObject();
         }
 
         .add(newXsqlvar);
     }

    
Makes the set of commands in the current batch empty. This method is optional.

Throws:
java.sql.SQLException if a database access error occurs or the driver does not support batch statements
Since:
1.2
See also:
What Is in the JDBC 2.0 API
 
     public void clearBatch() throws SQLException {
         .clear();
     }

    
Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. The int elements of the array that is returned are ordered to correspond to the commands in the batch, which are ordered according to the order in which they were added to the batch. The elements in the array returned by the method executeBatch may be one of the following:
  1. A number greater than or equal to zero -- indicates that the command was processed successfully and is an update count giving the number of rows in the database that were affected by the command's execution
  2. A value of -2-- indicates that the command was processed successfully but that the number of rows affected is unknown

    If one of the commands in a batch update fails to execute properly, this method throws a BatchUpdateException, and a JDBC driver may or may not continue to process the remaining commands in the batch. However, the driver's behavior must be consistent with a particular DBMS, either always continuing to process commands or never continuing to process commands. If the driver continues processing after a failure, the array returned by the method BatchUpdateException.getUpdateCounts will contain as many elements as there are commands in the batch, and at least one of the elements will be the following:

  3. A value of -3-- indicates that the command failed to execute successfully and occurs only if a driver continues to process commands after a command fails

A driver is not required to implement this method. The possible implementations and return values have been modified in the Java 2 SDK, Standard Edition, version 1.3 to accommodate the option of continuing to proccess commands in a batch update after a BatchUpdateException obejct has been thrown.

Returns:
an array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which commands were added to the batch.
Throws:
java.sql.SQLException if a database access error occurs or the driver does not support batch statements. Throws java.sql.BatchUpdateException(a subclass of SQLException) if one of the commands sent to the database fails to execute properly or attempts to return a result set.
Since:
1.3
See also:
What Is in the JDBC 2.0 API
 
     public int[] executeBatch() throws SQLException {
         Object syncObject = getSynchronizationObject();
         synchronized (syncObject) {
 
             boolean commit = false;
             try {
                 notifyStatementStarted();
 
                 ArrayList results = new ArrayList(.size());
                 Iterator iter = .iterator();
 
                 try {
                     while (iter.hasNext()) {
                         XSQLVAR[] data = (XSQLVAR[]) iter.next();
 
                         XSQLVAR[] vars = .getInSqlda().;
                         for (int i = 0; i < vars.lengthi++) {
                             FBField field = getField(i + 1);
                             if (field instanceof FBFlushableField) {
                                 vars[i].copyFrom(data[i], false);
                                 ((FBFlushableField)field).setCachedObject((CachedObject)data[i].);
                             } else {
                                 vars[i].copyFrom(data[i], true);
                             }
                                 
                             [i] = true;
                         }
 
                         try {
                             if (internalExecute())
                                 throw new BatchUpdateException(toArray(results));
 
                             int updateCount = getUpdateCount();
 
                             results.add(new Integer(updateCount));
 
                         } catch (SQLException ex) {
                             throw new BatchUpdateException(ex.getMessage(), ex
                                     .getSQLState(), ex.getErrorCode(),
                                     toArray(results));
                         }
                     }
 
                     commit = true;
 
                     return toArray(results);
 
                 } finally {
                     clearBatch();
                 }
             } finally {
                 notifyStatementCompleted(commit);
             }
         }
     }

    
Sets the designated parameter to the given Reader object, which is the given number of characters long. When a very large UNICODE value is input to a LONGVARCHAR parameter, it may be more practical to send it via a java.io.Reader object. The data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from UNICODE to the database char format.

Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
reader the java reader which contains the UNICODE data
length the number of characters in the stream
Throws:
java.sql.SQLException if a database access error occurs
Since:
1.2
See also:
What Is in the JDBC 2.0 API
    public void setCharacterStream(int parameterIndexReader readerint length)
            throws SQLException {
        getField(parameterIndex).setCharacterStream(readerlength);
        [parameterIndex - 1] = true;
    }
    
    public void setCharacterStream(int parameterIndexReader reader,
            long lengththrows SQLException {
        if (length > .)
            throw new FBDriverNotCapableException("Only length <= Integer.MAX_VALUE supported");
        setCharacterStream(parameterIndexreader, (int)length);
    }
    public void setCharacterStream(int parameterIndexReader reader)
            throws SQLException {
        throw new FBDriverNotCapableException();
    }
    
    
Sets the designated parameter to the given REF(<structured-type>) value.

Parameters:
i the first parameter is 1, the second is 2, ...
x an SQL REF value
Throws:
java.sql.SQLException if a database access error occurs
Since:
1.2
See also:
What Is in the JDBC 2.0 API
    public void setRef(int iRef xthrows SQLException {
        throw new FBDriverNotCapableException();
    }

    
Sets the designated parameter to the given Blob object.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
blob a Blob object that maps an SQL BLOB value
Throws:
java.sql.SQLException if a database access error occurs
Since:
1.2
See also:
What Is in the JDBC 2.0 API
    public void setBlob(int parameterIndexBlob blobthrows SQLException {
        
        // if the passed BLOB is not instance of our class, copy its content
        // into the our BLOB
        if (!(blob instanceof FBBlob)) {
            FBBlob fbb = new FBBlob();
            fbb.copyStream(blob.getBinaryStream());
            blob = fbb;
        } 
        
        getField(parameterIndex).setBlob((FBBlobblob);
        [parameterIndex - 1] = true;
    }
    
    public void setBlob(int parameterIndexInputStream inputStreamlong length)
            throws SQLException {
        throw new FBDriverNotCapableException();
    }
    public void setBlob(int parameterIndexInputStream inputStream)
            throws SQLException {
        FBBlob blob = new FBBlob();
        blob.copyStream(inputStream);
        setBlob(parameterIndexblob);
    }

    
Sets the designated parameter to the given Clob object.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
clob a Clob object that maps an SQL CLOB value
Throws:
java.sql.SQLException if a database access error occurs
Since:
1.2
    public void setClob(int parameterIndexClob clobthrows SQLException {
        // if the passed BLOB is not instance of our class, copy its content
        // into the our BLOB
        if (!(clob instanceof FBClob)) {
            FBClob fbc = new FBClob(new FBBlob());
            fbc.copyCharacterStream(clob.getCharacterStream());
            clob = fbc;
        } 
        
        getField(parameterIndex).setClob((FBClobclob);
        [parameterIndex - 1] = true;
    }
    
    public void setClob(int parameterIndexReader readerlong length)
            throws SQLException {
        throw new FBDriverNotCapableException();
    }
    public void setClob(int parameterIndexReader readerthrows SQLException {
        FBClob clob = new FBClob(new FBBlob());
        clob.copyCharacterStream(reader);
        setClob(parameterIndexclob);
    }

    
Sets the designated parameter to the given Array object. Sets an Array parameter.

Parameters:
i the first parameter is 1, the second is 2, ...
x an Array object that maps an SQL ARRAY value
Throws:
java.sql.SQLException if a database access error occurs
Since:
1.2
See also:
What Is in the JDBC 2.0 API
    public void setArray(int iArray xthrows SQLException {
        throw new FBDriverNotCapableException();
    }

    
Gets the number, types and properties of a ResultSet object's columns.

Returns:
the description of a ResultSet object's columns
Throws:
java.sql.SQLException if a database access error occurs
Since:
1.2
See also:
What Is in the JDBC 2.0 API
    public ResultSetMetaData getMetaData() throws SQLException {
        return new FBResultSetMetaData(.getOutSqlda().,
                );
    }

    
Sets the designated parameter to the given java.sql.Date value, using the given Calendar object. The driver uses the Calendar object to construct an SQL DATE value, which the driver then sends to the database. With a a Calendar object, the driver can calculate the date taking into account a custom timezone. If no Calendar object is specified, the driver uses the default timezone, which is that of the virtual machine running the application.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x the parameter value
cal the Calendar object the driver will use to construct the date
Throws:
java.sql.SQLException if a database access error occurs
Since:
1.2
See also:
What Is in the JDBC 2.0 API
    public void setDate(int parameterIndexDate xCalendar cal)
            throws SQLException {
        getField(parameterIndex).setDate(xcal);
        [parameterIndex - 1] = true;
    }

    
Sets the designated parameter to the given java.sql.Time value, using the given Calendar object. The driver uses the Calendar object to construct an SQL TIME value, which the driver then sends to the database. With a a Calendar object, the driver can calculate the time taking into account a custom timezone. If no Calendar object is specified, the driver uses the default timezone, which is that of the virtual machine running the application.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x the parameter value
cal the Calendar object the driver will use to construct the time
Throws:
java.sql.SQLException if a database access error occurs
Since:
1.2
See also:
What Is in the JDBC 2.0 API
    public void setTime(int parameterIndexTime xCalendar cal)
            throws SQLException {
        getField(parameterIndex).setTime(xcal);
        [parameterIndex - 1] = true;
    }

    
Sets the designated parameter to the given java.sql.Timestamp value, using the given Calendar object. The driver uses the Calendar object to construct an SQL TIMESTAMP value, which the driver then sends to the database. With a a Calendar object, the driver can calculate the timestamp taking into account a custom timezone. If no Calendar object is specified, the driver uses the default timezone, which is that of the virtual machine running the application.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
x the parameter value
cal the Calendar object the driver will use to construct the timestamp
Throws:
java.sql.SQLException if a database access error occurs
Since:
1.2
See also:
What Is in the JDBC 2.0 API
    public void setTimestamp(int parameterIndexTimestamp xCalendar cal)
            throws SQLException {
        getField(parameterIndex).setTimestamp(xcal);
        [parameterIndex - 1] = true;
    }

    
Sets the designated parameter to SQL NULL. This version of the method setNull should be used for user-defined types and REF type parameters. Examples of user-defined types include: STRUCT, DISTINCT, JAVA_OBJECT, and named array types.

Note: To be portable, applications must give the SQL type code and the fully-qualified SQL type name when specifying a NULL user-defined or REF parameter. In the case of a user-defined type the name is the type name of the parameter itself. For a REF parameter, the name is the type name of the referenced type. If a JDBC driver does not need the type code or type name information, it may ignore it. Although it is intended for user-defined and Ref parameters, this method may be used to set a null parameter of any JDBC type. If the parameter does not have a user-defined or REF type, the given typeName is ignored.

Parameters:
parameterIndex the first parameter is 1, the second is 2, ...
sqlType a value from java.sql.Types
typeName the fully-qualified name of an SQL user-defined type; ignored if the parameter is not a user-defined type or REF
Throws:
java.sql.SQLException if a database access error occurs
Since:
1.2
See also:
What Is in the JDBC 2.0 API
    public void setNull(int parameterIndexint sqlTypeString typeName)
            throws SQLException {
        // all nulls are represented the same irrespective of type
        setNull(parameterIndexsqlType); 
    }

    
Prepare fixed statement and initialize parameters.
    protected void prepareFixedStatement(String sqlboolean describeBind)
            throws GDSExceptionSQLException {
        super.prepareFixedStatement(sqldescribeBind);
        XSQLDA inSqlda = .getInSqlda();
        if (!describeBind && inSqlda == null) {
            inSqlda = new XSQLDA();
            inSqlda.sqln = 0;
            inSqlda.sqlvar = new XSQLVAR[0];
        }
        // initialize isParamSet member
         = new boolean[inSqlda.sqln];
         = new FBField[inSqlda.sqln];
        for (int i = 0; i < .i++) {
            final int fieldPos = i;
            FieldDataProvider dataProvider = new FieldDataProvider() {
                public byte[] getFieldData() {
                    return getXsqlvar(fieldPos + 1).;
                }
                public void setFieldData(byte[] data) {
                    getXsqlvar(fieldPos + 1). = data;
                }
            };
            // FIXME check if we can safely pass cached here
            [i] = FBField.createField(getXsqlvar(i + 1), dataProvider,
                false);
            if ([iinstanceof FBWorkaroundStringField)
                ((FBWorkaroundStringField[i])
                        .setTrimString();
        }
    }

    
Get the execution plan of this PreparedStatement

Returns:
The execution plan of the statement
    public String getExecutionPlan() throws FBSQLException {
        return super.getExecutionPlan();
    }

    
Get the statement type of this PreparedStatement. The returned value will be one of the TYPE_* constant values.

Returns:
The identifier for the given statement's type
    public int getStatementType() throws FBSQLException {
        return super.getStatementType();
    }
        return new FBParameterMetaData(.getInSqlda().);
    }
    
    // Methods not allowed to be used on PreparedStatement and CallableStatement
    
    @Override
    public ResultSet executeQuery(String sqlthrows SQLException {
        throw new FBSQLException();
    }
    
    @Override
    public int executeUpdate(String sqlthrows SQLException {
        throw new FBSQLException();
    }
    
    @Override
    public boolean execute(String sqlthrows SQLException {
        throw new FBSQLException();
    }
    
    @Override
    public void addBatch(String sqlthrows SQLException {
        throw new FBSQLException();
    }
    
    @Override
    public int executeUpdate(String sqlint autoGeneratedKeysthrows SQLException {
        throw new FBSQLException();
    }
    
    @Override
    public int executeUpdate(String sqlint[] columnIndexthrows SQLException {
        throw new FBSQLException();
    }
    
    @Override
    public int executeUpdate(String sqlString[] columnNamesthrows SQLException {
        throw new FBSQLException();
    }
    
    @Override
    public boolean execute(String sqlint autoGeneratedKeysthrows SQLException {
        throw new FBSQLException();
    }
    
    @Override
    public boolean execute(String sqlint[] columnIndexesthrows SQLException {
        throw new FBSQLException();
    }
    
    @Override 
    public boolean execute(String sqlString[] columnNamesthrows SQLException {
        throw new FBSQLException();
    }
New to GrepCode? Check out our FAQ X