Package oracle.jdbc.driver

Examples of oracle.jdbc.driver.OracleCallableStatement


            }
            callStringBuffer.append(")}");

            String callString = callStringBuffer.toString();

            OracleCallableStatement cstmt =
                (OracleCallableStatement) con.prepareCall(callString.toString());

            DOMPrinter domPrinter = new DOMPrinter();

            // Iterate through list of Param nodes.
            for (int paramIndex = 0; paramIndex < paramCount; paramIndex++) {

                // Get the node from the node list
                Node paramNode = paramNodeList.item(paramIndex);

                // The index position of the "?" parameter in the callable statement
                // is 2 more than the index position of the Param element in the
                // Java list we are traversing. The callable statement parameters
                // use 1-based indexing, unlike the 0-based indexing used in the
                // Java list, and the first callable statement parameter is
                // an output parameter reserved for a return value.

                int callableStatementParamIndex = paramIndex + 2;
                setCallableStatementParameterValue(cstmt,
                                                   callableStatementParamIndex,
                                                   procedureNameValue,
                                                   paramNode,
                                                   xmlParseUtils,
                                                   domPrinter,
                                                   id,
                                                   strDescriptor);

            } // End of loop through Param elements

            // Register the output parameter as cursor.
            cstmt.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);

            // Call the stored procedure to insert the data.
            try {
                cstmt.executeUpdate();

                // If the Procedure node had the IdColumnName attribute set,
                // retrieve the ID value using the column name.
                Console.displayDev("ID column name: ", idColumnName, true, "scb");

                if (idColumnName != null || writeData) {
                    ResultSet rs = null;

                    try {
                        // Get the return value
                        rs = cstmt.getCursor(1);
                        /*
                        ResultSetMetaData md = rs.getMetaData();
                        for (int k = 1; k < md.getColumnCount() + 1; k++) {
                            Console.displayDev("Column names", md.getColumnName(k) +
                                               " of type " + md.getColumnType(k), false, "scb");
                        } */

                        // Get id value as integer.
                        while (rs.next()) {
                            if (writeData) {
                                this.dataWriter.append(rs);
                            }
                            if (idColumnName != null) {
                                id = rs.getInt(idColumnName);
                                SQLWarning stmtWarning = cstmt.getWarnings();
                                SQLWarning rsWarning   = rs.getWarnings();
                                if (stmtWarning != null || rsWarning != null) {
                                    StringBuffer warningBuffer = new StringBuffer(100);
                                    warningBuffer.append("WARNING:");

                                    while (stmtWarning != null) {
                                        warningBuffer.append(" Stmt Message: "   + stmtWarning.getMessage() );
                                        warningBuffer.append(" Stmt SQLState: "  + stmtWarning.getSQLState() );
                                        warningBuffer.append(" Stmt ErrorCode: " + stmtWarning.getErrorCode() );
                                        stmtWarning = stmtWarning.getNextWarning();
                                    }
                                    while (rsWarning != null) {
                                        warningBuffer.append(" Rs Message: "   + rsWarning.getMessage() );
                                        warningBuffer.append(" Rs SQLState: "  + rsWarning.getSQLState() );
                                        warningBuffer.append(" Rs ErrorCode: " + rsWarning.getErrorCode() );
                                        rsWarning = rsWarning.getNextWarning();
                                    }
                                    super.msgEntry.setAppContext("callStoredProcedure()");
                                    super.msgEntry.setDocInfo(currentFilename);
                                    super.msgEntry.setMessageText("Warning calling stored procedure " +
                                                                  procedureNameValue +
                                                                  " from OracleDbUtils.callStoredProcedure().");
                                    super.msgEntry.setError( new String(warningBuffer) );
                                    logger.logWarning(super.msgEntry);
                                }
                            }   // end if idColumnName != null
                        }   // end while next record is available
                    }   // end try to get cursor
                    finally {
                        try {
                            if (writeData) {
                                this.dataWriter.write(this.currentFilename, procedureNameValue);
                            }
                            if (rs != null) {
                                rs.close();
                            }
                        }
                        catch (SQLException sqle) {
                            super.msgEntry.setAppContext("callStoredProcedure()");
                            super.msgEntry.setDocInfo(currentFilename);
                            super.msgEntry.setMessageText("Unable to close result set.");
                            StringBuffer buffer = new StringBuffer(100);
                            // Multiple exceptions may be chained together. Get all information.
                            while (sqle != null) {
                                buffer.append( "Message: "    + sqle.getMessage() );
                                buffer.append( " SQLState: "  + sqle.getSQLState() );
                                buffer.append( " ErrorCode: " + sqle.getErrorCode() );
                                sqle = sqle.getNextException();
                            }
                            super.msgEntry.setError( new String(buffer) );
                            logger.logWarning(super.msgEntry);
                        }
                    }
                } // end if idColumnName != null || writeData
                else {
                    SQLWarning stmtWarning = cstmt.getWarnings();
                    if (stmtWarning != null) {
                        StringBuffer warningBuffer = new StringBuffer(100);
                        warningBuffer.append("WARNING:");
                        while (stmtWarning != null) {
                            warningBuffer.append(" Stmt Message: "   + stmtWarning.getMessage() );
                            warningBuffer.append(" Stmt SQLState: "  + stmtWarning.getSQLState() );
                            warningBuffer.append(" Stmt ErrorCode: " + stmtWarning.getErrorCode() );
                            stmtWarning = stmtWarning.getNextWarning();
                        }
                        super.msgEntry.setAppContext("callStoredProcedure()");
                        super.msgEntry.setDocInfo(currentFilename);
                        super.msgEntry.setMessageText("Warning calling stored procedure " +
                                                      procedureNameValue +
                                                      " from OracleDbUtils.callStoredProcedure().");
                        super.msgEntry.setError( new String(warningBuffer) );
                        logger.logWarning(super.msgEntry);
                    }
                } // end if idColumnName == null && !writeData
            }
            catch (SQLException sqle) {

                boolean moveToBad;
                StringBuffer buffer = new StringBuffer(100);

                // Decide whether file should be moved to bad location.
                // If so, throw exception up to DBStoreProcessor for execution.
                if (moveToBadLocUponFailure != null &&
                    moveToBadLocUponFailure.equals(DBXmlConfig.YES)) {
                    moveToBad = true;
                }
                else {
                    moveToBad = false;
                }

                if (moveToBad) {
                    buffer.append("Error calling stored procedure ");
                    buffer.append(procedureNameValue);
                    buffer.append(" in OracleDbUtils.callStoredProcedure processing file ");
                    buffer.append(currentFilename);
                    buffer.append(":");
                    // Multiple exceptions may be chained together. Get all information.
                    while (sqle != null) {
                        buffer.append( " Message: "   + sqle.getMessage() );
                        buffer.append( " SQLState: "  + sqle.getSQLState() );
                        buffer.append( " ErrorCode: " + sqle.getErrorCode() );
                        sqle = sqle.getNextException();
                    }
                    throw new DbStoredProcedureException( new String(buffer) );
                }
                super.msgEntry.setAppContext("callStoredProcedure()");
                super.msgEntry.setDocInfo(currentFilename);
                super.msgEntry.setMessageText("Error calling stored procedure " +
                                              procedureNameValue +
                                              " from OracleDbUtils.callStoredProcedure().");
                // Multiple exceptions may be chained together. Get all information.
                while (sqle != null) {
                    buffer.append( "Message: "    + sqle.getMessage() );
                    buffer.append( " SQLState: "  + sqle.getSQLState() );
                    buffer.append( " ErrorCode: " + sqle.getErrorCode() );
                    sqle = sqle.getNextException();
                }
                super.msgEntry.setError( new String(buffer) );
                logger.logWarning(super.msgEntry);
                continue;
            }
            finally {
                try {
                    if (cstmt != null) {
                        cstmt.close();
                    }
                }
                catch (SQLException sqle) {
                    super.msgEntry.setAppContext("callStoredProcedure()");
                    super.msgEntry.setDocInfo(currentFilename);
View Full Code Here


      "{? = call S_INSERTMAP(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}";

  public static void storeCatMapping(CategoryMapping cm, Connection con,
                                     int articleId) throws SQLException {

    OracleCallableStatement ocs = null;
    ResultSet rs = null;
    try {
      ocs = (OracleCallableStatement) con.prepareCall(INSERT_MAP_SQL);

      if (ocs != null) {
        ocs.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
        setContentTypeId(cm.getContentTypeId(), ocs);
        setArticleId(articleId, ocs);
        setCategoryId(0, ocs);
        setRank(999, ocs);
        setUserName(cm.getUserName(), ocs);
        setStartTime(cm.getStartTime(), ocs);
        setEndTime(cm.getEndTime(), ocs);
        setPubId(0, ocs);
        setUpdateTime(null, ocs);
        setAltName("", ocs);
        setAltDesc("", ocs);
        setCatName(cm.getCategoryName(), ocs);
        setPubName(cm.getPubName(), ocs);
        setStatus(1, ocs);
        setFromFeed(1, ocs);
        ocs.execute();
        rs = ocs.getCursor(1);
        con.commit();
      }
    }
    finally {
      try {
        if (rs != null) {
          rs.close();
        }
      }
      catch (SQLException sqle) {
        // Do nothing.
        rs = null;
      }
      try {
        if (ocs != null) {
          ocs.close();
        }
      }
      catch (SQLException s) {
        // Do nothing.
        ocs = null;
View Full Code Here

  public static int storePhoto(Photo photo, int cGroupId, Connection con) throws SQLException {

    int photoID = 0;

    OracleCallableStatement ocs = null;

    try {
      ocs = (OracleCallableStatement) con.prepareCall(INSERT_PHOTO_SQL);
      if (ocs != null) {
        setPhotoId(photo.getPhotoId(), ocs);
        setCGroupId(cGroupId, ocs);
        // @todo: Where will rank come from?
        setRank(999, ocs);
        setPubId(photo.getPubId(), ocs);
        setCategoryId(photo.getCategoryId(), ocs);
        setImage(photo.getImage(), ocs);
        setImageHeight(photo.getImageHeight(), ocs);
        setImageWidth(photo.getImageWidth(), ocs);
        setCaption(photo.getCaption(), ocs);
        setCredit(photo.getCredit(), ocs);
        setMimeType(photo.getMimeType(), ocs);
        setCreateBy("Insert process", ocs);
        setOrigImageName(photo.getOrigImageName(), ocs);
        setIsThumbnail(photo.isIsThumbnail(), ocs);
        setAdminThumbnail(photo.getAdminThumbnail(), ocs);
        setNeedsResize(photo.needsResize(), ocs);
        // @todo: Can we get the resize info from the feed?
        setResizeImageSize(0, ocs);

        ocs.registerOutParameter(1, java.sql.Types.INTEGER);
        ocs.execute();
        // Get id value as integer.
        photoID = ocs.getInt(1);
        con.commit();
      }
    }
    finally {
      try {
        if (ocs != null) {
          ocs.close();
        }
      }
      catch (SQLException sql) {
        // Do nothing.
        ocs = null;
View Full Code Here

  public static int storeRelatedPackage(ContentPackage cp, Connection con) throws SQLException {

    int relatedPkgId = -1;
    ResultSet rs = null;
    OracleCallableStatement callableStmt = null;

    try {
      callableStmt = (OracleCallableStatement) con.prepareCall(
          RelatedPackageCSHelper.INSERT_PKG_SQL);

      Date now = java.util.Calendar.getInstance().getTime();
      callableStmt.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
      setPackageId(0, callableStmt);
      setPackageDesc(getPackageDescFromPackage(cp), callableStmt);
      setSiteId(cp.getSiteId(), callableStmt);
      setPubId(cp.getPubId(), callableStmt);
      setStatus(1, callableStmt);
      setCreateTime(now, callableStmt);
      setUpdateTime(now, callableStmt);
      setCreateBy("Insert Process", callableStmt);
      setUpdateBy("Insert Process", callableStmt);

      callableStmt.executeUpdate();

      // Get the return value
      rs = callableStmt.getCursor(1);

      // Get id value as integer.
      while (rs.next()) {
        relatedPkgId = rs.getInt(RelatedPackageCSHelper.PKG_ID_COLUMN_NAME);
        Console.displayDev("RelPkgCSHelper", "Pkg id is: " + relatedPkgId, true,
                           "scb");
      }
      con.commit();
    }
    finally {
      // Try to close result set and callable statement.  If the package
      // creation has failed, we shouldn't try to add
      try {
        if (rs != null) {
          rs.close();
        }
      }
      catch (SQLException sqle) {
        // Do nothing.
        rs = null;
      }

      try {
        if (callableStmt != null) {
          callableStmt.close();
        }
      }
      catch (SQLException s) {
        // Do nothing
        callableStmt = null;
View Full Code Here

    return relatedPkgId;
  }

  private static void addArticleToPackage(int pkgId, BasicArticle article, Connection con)
      throws SQLException {
    OracleCallableStatement callableStmt = null;
    ResultSet rs = null;
    try {
      callableStmt = (OracleCallableStatement) con.prepareCall(
          RelatedPackageCSHelper.ADD_PKG_MAP_SQL);
      callableStmt.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
      callableStmt.setInt(2, pkgId);
      callableStmt.setInt(3, article.getArticleId());
      callableStmt.setInt(4, BasicArticle.CONTENT_TYPE_ID);
      callableStmt.executeUpdate();
      rs = callableStmt.getCursor(1);
      con.commit();
    }
    finally {
      try {
        if (rs != null) {
          rs.close();
        }
      }
      catch (SQLException se) {
        // Do nothing
        rs = null;
      }

      try {
        if (callableStmt != null) {
          callableStmt.close();
        }
      }
      catch (SQLException s) {
        // Do nothing
        callableStmt = null;
View Full Code Here

    }
  }

  private static void addPhotoPackageToPackage(int pkgId, PhotoPackage pkg, Connection con) throws SQLException {

    OracleCallableStatement callableStmt = null;
    ResultSet rs = null;
    try {
      callableStmt = (OracleCallableStatement) con.prepareCall(
          RelatedPackageCSHelper.ADD_PKG_MAP_SQL);

      callableStmt.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
      callableStmt.setInt(2, pkgId);
      callableStmt.setInt(3, pkg.getPackageId());
      callableStmt.setInt(4, PhotoPackage.CONTENT_TYPE_ID);
      callableStmt.executeUpdate();
      rs = callableStmt.getCursor(1);
      con.commit();
    }
    finally {
      try {
        if (rs != null) {
          rs.close();
        }
      }
      catch (SQLException se) {
        // Do nothing
        rs = null;
      }

      try {
        if (callableStmt != null) {
          callableStmt.close();
        }
      }
      catch (SQLException s) {
        // Do nothing
        callableStmt = null;
View Full Code Here

      "{call ? := pkg_photo_packages_manager.savePhotoPackage(?,?,?,?,?,?,?,?,?)}";

  public static int storePhotoPackage(PhotoPackage photoPkg, Connection con) throws SQLException {

    int photoPkgId = 0;
    OracleCallableStatement ocs = null;

    try {
        ocs = (OracleCallableStatement) con.prepareCall(
          PhotoPackageCSHelper.INSERT_PHOTO_PACKAGE_SQL);

        if (ocs != null && photoPkg != null) {
          setCGroupDesc(photoPkg.getDescription(), ocs);
          setContentTypeId(PhotoPackage.CONTENT_TYPE_ID, ocs);
          setPubId(photoPkg.getPubId(), ocs);
          setCreateBy(photoPkg.getCreateBy(), ocs);
          setNational(photoPkg.isNational(), ocs);
          setCategoryId(photoPkg.getCategoryId(), ocs);
          setStartTime(photoPkg.getStartTime(), ocs);
          setEndTime(photoPkg.getEndTime(), ocs);
          setKeywords(photoPkg.getKeywords(), ocs);

          ocs.registerOutParameter(1, java.sql.Types.INTEGER);
          ocs.execute();
          // Get id value as integer.
          photoPkgId = ocs.getInt(1);
        }
        con.commit();
    }
    finally {
      if (ocs != null) {
        try {
          ocs.close();
        }
        catch (SQLException sql) {
          // Do nothing.
          ocs = null;
        }
View Full Code Here

  /**
   * @return database Id of article
   */
  public static int storeArticle(BasicArticle ba, Connection con) throws SQLException {

    OracleCallableStatement ocs = null;
    ResultSet rs = null;
    int id = 0;

    try {
      ocs = (OracleCallableStatement) con.prepareCall(INSERT_ARTICLE_SQL);
      if (ocs != null && ba != null) {
        setArticleId(ba.getArticleId(), ocs);
        setPubId(ba.getPubId(), ocs);
        setCategoryId(ba.getCategoryId(), ocs);
        setStartTime(ba.getStartTime(), ocs);
        setEndTime(ba.getEndTime(), ocs);
        setMemo("", ocs);
        setCorrection("", ocs);
        setHeadline(ba.getHeadline(), ocs);
        setLead(ba.getLead(), ocs);
        setDateline(ba.getDateline(), ocs);
        setKeywords("", ocs);
        setPubData("", ocs);
        setVersionNum(ba.getVersionNum(), ocs);
        setDocType(0, ocs);
        setShortHeadline(ba.getShortHeadline(), ocs);
        setByline(ba.getByline(), ocs);
        setData("", ocs);
        setBody(ba.getBody(), ocs, con);
        setRank(ba.getRank(), ocs);
        setHeadline2(ba.getHeadline2(), ocs);
        setByCredit(ba.getBycredit(), ocs);
        setWebLead(ba.getWebLead(), ocs);
        setUseTopixLinks(0, ocs);
        setFilename(ba.getFileName(), ocs);
        setDisableIndex(ba.getDisableIndex(), ocs);
        setColumnistId(ba.getColumnistId(), ocs);
        setWebHeadline(ba.getWebHeadline(), ocs);
        setCustomURL(ba.getCustomURL(), ocs);
        setLeadin("", ocs);
        setStatus(ba.getStatus(), ocs);
        setCreateTime(null, ocs);
        setUpdateTime(null, ocs);
        setCreateBy(ba.getCreateBy(), ocs);
        setUpdateBy(ba.getUpdateBy(), ocs);
        setCategoryName(ba.getCatName(), ocs);
        setPubName(ba.getPubName(), ocs);
        setColumnistName(ba.getColumnistName(), ocs);
        setAltName("", ocs);
        setAltDesc("", ocs);
        setDocSourceType(ba.getDocSourceType(), ocs);
        setDocSource(ba.getDocSource(), ocs);
        setSig(ba.getSig(), ocs);
        setKicker(ba.getKicker(), ocs);
        if (ba.isHasTable()) {
          setHasTable(1, ocs);
        }
        else {
          setHasTable(0, ocs);
        }
        setNpSection(ba.getNpSection(), ocs);
        setNpPage(ba.getNpPage(), ocs);
        setNpEdition(ba.getNpEdition(), ocs);
        if (ba.isMapToTaxonomy()) {
          setMapToTaxonomy(1, ocs);
        }
        else {
          setMapToTaxonomy(0, ocs);
        }
        setPubDate(ba.getPubDate(), ocs);
        setOverride(1, ocs);

        ocs.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
        ocs.executeUpdate();
        // Get the return value
        rs = ocs.getCursor(1);

        // Get id value as integer.
        while (rs.next()) {
          id = rs.getInt("article_id");
          // After retrieving the article Id from the database, store it in
          // the article object.
          ba.setArticleId(id);
        }
        con.commit();
      }
    }
    finally {
      try {
        if (rs != null) {
          rs.close();
        }
      }
      catch (SQLException sqle) {
        // Do nothing.
        rs = null;
      }
      try {
        if (ocs != null) {
          ocs.close();
        }
      }
      catch (SQLException s) {
        // Do nothing.
        ocs = null;
View Full Code Here

                                     String originalFileName,
                                     Connection con,
                                     DataWriter dataWriter)
    throws SQLException {

    OracleCallableStatement ocs = null;
    ResultSet rs = null;

    try {
        ocs = (OracleCallableStatement) con.prepareCall(GET_ARTICLE_URLS_SQL);

        if (ocs != null && article != null) {

            setArticleId(article.getArticleId(), ocs);
            ocs.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
            ocs.executeUpdate();

            // Get the return value
            rs = ocs.getCursor(1);

            /*
            ResultSetMetaData md = rs.getMetaData();
            for (int k = 1; k < md.getColumnCount() + 1; k++) {
                Console.displayDev("Column name: ", md.getColumnName(k) +
                                   " of type " + md.getColumnType(k), true, "bh");
            }
            */

            while (rs.next()) {
                dataWriter.append(rs);
            }
        }
      }
      finally {
        try {
            dataWriter.write(originalFileName, URL_RETRIEVAL_FUNCTION);

            if (rs != null) {
                rs.close();
            }
        }
        catch (SQLException sqle) {
          // Do nothing.
          rs = null;
        }
        try {
          if (ocs != null) {
            ocs.close();
          }
        }
        catch (SQLException s) {
          // Do nothing.
          ocs = null;
View Full Code Here

TOP

Related Classes of oracle.jdbc.driver.OracleCallableStatement

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.