Examples of CallableStatement


Examples of java.sql.CallableStatement

    private void testExecuteCall() throws SQLException {
        deleteDb("batchUpdates");
        conn = getConnection("batchUpdates");
        stat = conn.createStatement();
        stat.execute("CREATE ALIAS updatePrices FOR \"" + getClass().getName() + ".updatePrices\"");
        CallableStatement call = conn.prepareCall("{call updatePrices(?, ?)}");
        call.setString(1, "Hello");
        call.setFloat(2, 1.4f);
        call.addBatch();
        call.setString(1, "World");
        call.setFloat(2, 3.2f);
        call.addBatch();
        int[] updateCounts = call.executeBatch();
        int total = 0;
        for (int t : updateCounts) {
            total += t;
        }
        assertEquals(4, total);
View Full Code Here

Examples of java.sql.CallableStatement

    }
    else
    {
      if (callableStatementUsed)
      {
        final CallableStatement pstmt = getConnection(parameters).prepareCall
            (translatedQuery, getBestResultSetType(parameters), ResultSet.CONCUR_READ_ONLY);
        if (isCallableStatementQuery(translatedQuery))
        {
          pstmt.registerOutParameter(1, Types.OTHER);
          parametrize(parameters, preparedParameterNames, pstmt, false, 1);
        }
        else
        {
          parametrize(parameters, preparedParameterNames, pstmt, false, 0);
        }
        statement = pstmt;
      }
      else
      {
        final PreparedStatement pstmt = getConnection(parameters).prepareStatement
            (translatedQuery, getBestResultSetType(parameters), ResultSet.CONCUR_READ_ONLY);
        parametrize(parameters, preparedParameterNames, pstmt, isExpandArrays(), 0);
        statement = pstmt;
      }
    }

    final Object queryLimit = parameters.get(DataFactory.QUERY_LIMIT);
    try
    {
      if (queryLimit instanceof Number)
      {
        final Number i = (Number) queryLimit;
        final int max = i.intValue();
        if (max > 0)
        {
          statement.setMaxRows(max);
        }
      }
    }
    catch (SQLException sqle)
    {
      // this fails for MySQL as their driver is buggy. We will not add workarounds here, as
      // all drivers are buggy and this is a race we cannot win. Put pressure on the driver
      // manufacturer instead.
      logger.warn("Driver indicated error: Failed to set query-limit: " + queryLimit, sqle);
    }
    final Object queryTimeout = parameters.get(DataFactory.QUERY_TIMEOUT);
    try
    {
      if (queryTimeout instanceof Number)
      {
        final Number i = (Number) queryTimeout;
        final int seconds = i.intValue();
        if (seconds > 0)
        {
          statement.setQueryTimeout(seconds);
        }
      }
    }
    catch (SQLException sqle)
    {
      logger.warn("Driver indicated error: Failed to set query-timeout: " + queryTimeout, sqle);
    }

    // Track the currently running statement - just in case someone needs to cancel it
    final ResultSet res;
    try
    {
      currentRunningStatement = statement;
      if (preparedParameterNames.length == 0)
      {
        res = statement.executeQuery(translatedQuery);
      }
      else
      {
        final PreparedStatement pstmt = (PreparedStatement) statement;
        res = pstmt.executeQuery();
      }
    }
    finally
    {
      currentRunningStatement = null;
View Full Code Here

Examples of java.sql.CallableStatement

  public Any m_call(Context context, String query)
  {
    Connection conn = null;
    try {
      conn = getConnection();
      CallableStatement stmt = conn.prepareCall(query);
      return new AnyStatement(stmt);
    } catch (SQLException e) {
      if (conn != null) {
        try {
          conn.close();
View Full Code Here

Examples of java.sql.CallableStatement

  }


  public Any getAttribute(Context context, String attribute)
  { 
    CallableStatement stmt = _callable;
    if (stmt != null) {
      try {
        return SQLUtil.getField(stmt, getMetaData(), toColumnIndex(attribute));
      } catch (SQLException e) {
        throw context.exception(e);
View Full Code Here

Examples of java.sql.CallableStatement



  public Any setAttribute(Context context, String attribute, Any value)
  { 
    CallableStatement stmt = _callable;
    try {
      SQLUtil.setField(_statement, toColumnIndex(attribute), value);
    } catch (SQLException e) {
      throw context.exception(e);
    }
View Full Code Here

Examples of java.sql.CallableStatement

  }
 

  public Any getReference(Context context, Any index)
  { 
    CallableStatement stmt = _callable;
    if (stmt != null) {
      try {
        return SQLUtil.getField(stmt, getMetaData(), toColumnIndex(index));
      } catch (SQLException e) {
        throw context.exception(e);
View Full Code Here

Examples of java.sql.CallableStatement



  public Any setReference(Context context, Any index, Any value)
  { 
    CallableStatement stmt = _callable;
    try {
      _index = toColumnIndex(index);
      SQLUtil.setField(_statement, _index, value);
    } catch (SQLException e) {
      throw context.exception(e);
View Full Code Here

Examples of java.sql.CallableStatement

  }


  public Any setReference(Context context, Any value)
  { 
    CallableStatement stmt = _callable;
    try {
      SQLUtil.setField(_statement, ++_index, value);
    } catch (SQLException e) {
      throw context.exception(e);
    }
View Full Code Here

Examples of java.sql.CallableStatement

  /// @return this
  /// @throws SQLError if an error occured
  public static final Object[] p_register = { null, "column", "type", "*scale", null };
  public Any m_register(Context context, int column, int type, Any scale)
  {
    CallableStatement stmt = _callable;
    if (stmt != null) {
      try {
        if (scale == null) {
          stmt.registerOutParameter(column, type);
        } else {
          stmt.registerOutParameter(column, type, scale.toInt());
        }
      } catch (SQLException e) {
        throw context.exception(e);
      }
    }
View Full Code Here

Examples of java.sql.CallableStatement

  }

  // ----------------------------------------------------------

  public boolean load(JDCConnection oConn, Object aPK[]) throws SQLException {
    CallableStatement oStmt;
    String sNmMicrosite;
    boolean bRetVal;

    if (DebugFile.trace) {
      DebugFile.writeln("Begin MicrositeDB.load([Connection], {" + aPK[0] + "}");
      DebugFile.incIdent();
    }

    if (oConn.getDataBaseProduct()==JDCConnection.DBMS_ORACLE ||
        oConn.getDataBaseProduct()==JDCConnection.DBMS_MSSQL  ||
        oConn.getDataBaseProduct()==JDCConnection.DBMS_MYSQL) {

      if (DebugFile.trace)
        DebugFile.writeln("Connection.prepareCall({ call k_sp_read_microsite ('" + aPK[0] + "',?,?,?,?) }");

      oStmt = oConn.prepareCall("{ call k_sp_read_microsite (?,?,?,?,?) }");

      clear();

      oStmt.setObject(1, aPK[0], Types.CHAR);       // gu_microsite
      oStmt.registerOutParameter(2, Types.INTEGER); // id_app
      oStmt.registerOutParameter(3, Types.VARCHAR); // nm_microsite
      oStmt.registerOutParameter(4, Types.VARCHAR); // path_metadata
      oStmt.registerOutParameter(5, Types.CHAR);    // gu_workarea

      if (DebugFile.trace) DebugFile.writeln("CallableStatement.execute()");

      oStmt.execute();

      sNmMicrosite = oStmt.getString(3);

      bRetVal = (null!=sNmMicrosite);

      put (DB.gu_microsite, aPK[0]);

      if (bRetVal) {
        put(DB.id_app, oStmt.getInt(2));
        put(DB.nm_microsite, oStmt.getString(3));
        put(DB.path_metadata, oStmt.getString(4));

        if (oStmt.getObject(5)!=null) put(DB.gu_workarea, oStmt.getString(5).trim());
      }

    oStmt.close();
    }
    else
      bRetVal = super.load(oConn, aPK);

    if (DebugFile.trace) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.