Package org.apache.derby.iapi.sql

Examples of org.apache.derby.iapi.sql.PreparedStatement


          }
        }

        // Get the statement. We don't care if it's invalid, because it
        // will be recompiled when we execute it if needed (DERBY-3024).
        PreparedStatement ps = a.getPreparedStatement();

        /*
        ** WARNING WARNING
        **
        ** Any state set in the activation before execution *must* be copied
        ** to the new activation in GenericActivationHolder.execute() when
        ** the statement has been recompiled. State such as
        ** singleExecution, cursorName, holdability, maxRows.
        */

        if (cursorName != null)
        {
          a.setCursorName(cursorName);
        }
               
                boolean executeHoldable = getExecuteHoldable();
        a.setResultSetHoldability(executeHoldable);

        //reset the activation to clear warnings
        //and clear existing result sets in case this has been cached
        a.reset();
        a.setMaxRows(maxRows);
                ResultSet resultsToWrap = ps.execute(a, timeoutMillis);
                addWarning(ps.getCompileTimeWarnings());
        addWarning(a.getWarnings());


        if (resultsToWrap.returnsRows()) {

                    // The statement returns rows, so calling it with
                    // executeUpdate() is not allowed.
                    if (executeUpdate) {
                        throw StandardException.newException(
                                SQLState.LANG_INVALID_CALL_TO_EXECUTE_UPDATE);
                    }

          EmbedResultSet lresults = factory.newEmbedResultSet(getEmbedConnection(), resultsToWrap, forMetaData, this, ps.isAtomic());
          results = lresults;


          // Set up the finalization of the ResultSet to
          // mark the activation as unused. It will be
          // closed sometime later by the connection
          // outside of finalization.
          if (a.isSingleExecution())
            lresults.singleUseActivation = a;

          updateCount = -1;
          retval = true;
        }
        else {

          // Only applipable for an insert statement, which does not return rows.
          //the auto-generated keys resultset will be null if used for non-insert statement
          if (a.getAutoGeneratedKeysResultsetMode() && (resultsToWrap.getAutoGeneratedKeysResultset() != null))
          {
            resultsToWrap.getAutoGeneratedKeysResultset().open();
            autoGeneratedKeysResultSet = factory.newEmbedResultSet(getEmbedConnection(),
              resultsToWrap.getAutoGeneratedKeysResultset(), false, this, ps.isAtomic());
          }

          updateCount = resultsToWrap.modifiedRowCount();
          results = null; // note that we have none.

View Full Code Here


    AlterTableConstantAction.executeUpdate(lcc, updateStmt);
  }

  private static void executeUpdate(LanguageConnectionContext lcc, String updateStmt) throws StandardException
  {
    PreparedStatement ps = lcc.prepareInternalStatement(updateStmt);

        // This is a substatement; for now, we do not set any timeout
        // for it. We might change this behaviour later, by linking
        // timeout to its parent statement's timeout settings.
    ResultSet rs = ps.executeSubStatement(lcc, true, 0L);
    rs.close();
  }
View Full Code Here

    String maxStmt = "SELECT " + maxStr + "(\"" + columnName + "\")"  +
        "FROM \"" + td.getSchemaName() + "\".\"" + td.getName() + "\"";


    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    PreparedStatement ps = lcc.prepareInternalStatement(maxStmt);

        // This is a substatement, for now we do not set any timeout for it
        // We might change this later by linking timeout to parent statement
    ResultSet rs = ps.executeSubStatement(lcc, false, 0L);
    DataValueDescriptor[] rowArray = rs.getNextRow().getRowArray();
    rs.close();
    rs.finish();

    return rowArray[0].getLong();
View Full Code Here

    SQLText = sql;   

    try {
      Activation activation;
      try {
        PreparedStatement preparedStatement = lcc.prepareInternalStatement
            (lcc.getDefaultSchema(), sql, resultSetConcurrency==
                        java.sql.ResultSet.CONCUR_READ_ONLY, false);
        activation =
          preparedStatement.getActivation(lcc, resultSetType ==
                        java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE);
        checkRequiresCallableStatement(activation);
                InterruptStatus.restoreIntrFlagIfSeen(lcc);
       } catch (Throwable t) {
        throw handleException(t);
View Full Code Here

          }
        }

        // Get the statement. We don't care if it's invalid, because it
        // will be recompiled when we execute it if needed (DERBY-3024).
        PreparedStatement ps = a.getPreparedStatement();

        /*
        ** WARNING WARNING
        **
        ** Any state set in the activation before execution *must* be copied
        ** to the new activation in GenericActivationHolder.execute() when
        ** the statement has been recompiled. State such as
        ** singleExecution, cursorName, holdability, maxRows.
        */

        if (cursorName != null)
        {
          a.setCursorName(cursorName);
        }
               
                boolean executeHoldable = getExecuteHoldable();
        a.setResultSetHoldability(executeHoldable);

        //reset the activation to clear warnings
        //and clear existing result sets in case this has been cached
        a.reset();
        a.setMaxRows(maxRows);
                ResultSet resultsToWrap = ps.execute(a, timeoutMillis);
                addWarning(ps.getCompileTimeWarnings());
        addWarning(a.getWarnings());


        if (resultsToWrap.returnsRows()) {

                    // The statement returns rows, so calling it with
                    // executeUpdate() is not allowed.
                    if (executeUpdate) {
                        throw StandardException.newException(
                                SQLState.LANG_INVALID_CALL_TO_EXECUTE_UPDATE);
                    }

          EmbedResultSet lresults = factory.newEmbedResultSet(getEmbedConnection(), resultsToWrap, forMetaData, this, ps.isAtomic());
          results = lresults;


          // Set up the finalization of the ResultSet to
          // mark the activation as unused. It will be
          // closed sometime later by the connection
          // outside of finalization.
          if (a.isSingleExecution())
            lresults.singleUseActivation = a;

          updateCount = -1L;
          retval = true;
        }
        else {

          // Only applipable for an insert statement, which does not return rows.
          //the auto-generated keys resultset will be null if used for non-insert statement
          if (a.getAutoGeneratedKeysResultsetMode() && (resultsToWrap.getAutoGeneratedKeysResultset() != null))
          {
            resultsToWrap.getAutoGeneratedKeysResultset().open();
            autoGeneratedKeysResultSet = factory.newEmbedResultSet(getEmbedConnection(),
              resultsToWrap.getAutoGeneratedKeysResultset(), false, this, ps.isAtomic());
          }

          updateCount = resultsToWrap.modifiedRowCount();
          results = null; // note that we have none.

View Full Code Here

    }

  public void rePrepare(LanguageConnectionContext lcc)
    throws StandardException {
    if (!upToDate()) {
      PreparedStatement ps = statement.prepare(lcc);

      if (SanityManager.DEBUG)
        SanityManager.ASSERT(ps == this, "ps != this");
    }
  }
View Full Code Here

    AlterTableConstantAction.executeUpdate(lcc, updateStmt);
  }

  private static void executeUpdate(LanguageConnectionContext lcc, String updateStmt) throws StandardException
  {
    PreparedStatement ps = lcc.prepareInternalStatement(updateStmt);

        // This is a substatement; for now, we do not set any timeout
        // for it. We might change this behaviour later, by linking
        // timeout to its parent statement's timeout settings.
    ResultSet rs = ps.execute(lcc, true, 0L);
    rs.close();
    rs.finish();
  }
View Full Code Here

    String maxStmt = "SELECT " + maxStr + "(\"" + columnName + "\")"  +
        "FROM \"" + td.getSchemaName() + "\".\"" + td.getName() + "\"";


    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    PreparedStatement ps = lcc.prepareInternalStatement(maxStmt);

        // This is a substatement, for now we do not set any timeout for it
        // We might change this later by linking timeout to parent statement
    ResultSet rs = ps.execute(lcc, false, 0L);
    DataValueDescriptor[] rowArray = rs.getNextRow().getRowArray();
    rs.close();
    rs.finish();

    return rowArray[0].getLong();
View Full Code Here

    AlterTableConstantAction.executeUpdate(lcc, updateStmt);
  }

  private static void executeUpdate(LanguageConnectionContext lcc, String updateStmt) throws StandardException
  {
    PreparedStatement ps = lcc.prepareInternalStatement(updateStmt);

        // This is a substatement; for now, we do not set any timeout
        // for it. We might change this behaviour later, by linking
        // timeout to its parent statement's timeout settings.
    ResultSet rs = ps.execute(lcc, true, 0L);
    rs.close();
    rs.finish();
  }
View Full Code Here

    String maxStmt = "SELECT " + maxStr + "(\"" + columnName + "\")"  +
        "FROM \"" + td.getSchemaName() + "\".\"" + td.getName() + "\"";


    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    PreparedStatement ps = lcc.prepareInternalStatement(maxStmt);

        // This is a substatement, for now we do not set any timeout for it
        // We might change this later by linking timeout to parent statement
    ResultSet rs = ps.execute(lcc, false, 0L);
    DataValueDescriptor[] rowArray = rs.getNextRow().getRowArray();
    rs.close();
    rs.finish();

    return rowArray[0].getLong();
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.sql.PreparedStatement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.