public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
    BigDecimal bd =
        (BigDecimal)
            Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.DECIMAL, null);

    return bd.setScale(scale);
  }
 public byte[] getBytes(int parameterIndex) throws SQLException {
   return ((byte[])
       Support.convert(
           this,
           getOutputValue(parameterIndex),
           java.sql.Types.VARBINARY,
           connection.getCharset()));
 }
  public URL getURL(int parameterIndex) throws SQLException {
    String url =
        (String)
            Support.convert(
                this,
                getOutputValue(parameterIndex),
                java.sql.Types.VARCHAR,
                connection.getCharset());

    try {
      return new java.net.URL(url);
    } catch (MalformedURLException e) {
      throw new SQLException(Messages.get("error.resultset.badurl", url), "22000");
    }
  }
 public Timestamp getTimestamp(int parameterIndex) throws SQLException {
   return (Timestamp)
       Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.TIMESTAMP, null);
 }
 public Date getDate(int parameterIndex) throws SQLException {
   return (java.sql.Date)
       Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.DATE, null);
 }
 public BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
   return (BigDecimal)
       Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.DECIMAL, null);
 }
 public String getString(int parameterIndex) throws SQLException {
   return (String)
       Support.convert(
           this, getOutputValue(parameterIndex), java.sql.Types.VARCHAR, connection.getCharset());
 }
 public short getShort(int parameterIndex) throws SQLException {
   return ((Integer)
           Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.SMALLINT, null))
       .shortValue();
 }
 public boolean getBoolean(int parameterIndex) throws SQLException {
   return ((Boolean) Support.convert(this, getOutputValue(parameterIndex), BOOLEAN, null))
       .booleanValue();
 }
 public int getInt(int parameterIndex) throws SQLException {
   return ((Integer)
           Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.INTEGER, null))
       .intValue();
 }
 public long getLong(int parameterIndex) throws SQLException {
   return ((Long)
           Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.BIGINT, null))
       .longValue();
 }
 public float getFloat(int parameterIndex) throws SQLException {
   return ((Double)
           Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.FLOAT, null))
       .floatValue();
 }
 public double getDouble(int parameterIndex) throws SQLException {
   return ((Double)
           Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.DOUBLE, null))
       .doubleValue();
 }
 public byte getByte(int parameterIndex) throws SQLException {
   return ((Integer)
           Support.convert(this, getOutputValue(parameterIndex), java.sql.Types.TINYINT, null))
       .byteValue();
 }
  public void insertRow() throws SQLException {
    checkOpen();

    checkUpdateable();

    if (!onInsertRow) {
      throw new SQLException(Messages.get("error.resultset.notinsrow"), "24000");
    }

    if (!tempResultSet) {
      //
      // Construct an SQL INSERT statement
      //
      StringBuffer sql = new StringBuffer(128);
      String dbName = columns[0].catalog;
      String userName = columns[0].schema;
      String tableName = columns[0].tableName;
      ArrayList params = new ArrayList();
      sql.append("INSERT INTO ");
      if (dbName != null) {
        sql.append(dbName);
        sql.append('.');
        if (userName == null) {
          sql.append('.');
        }
      }
      if (userName != null) {
        sql.append(userName);
        sql.append('.');
      }
      sql.append(tableName);
      int sqlLen = sql.length();
      //
      // Create column list
      //
      sql.append(" (");
      int count = 0;
      for (int i = 0; i < columnCount; i++) {
        if (insertRow[i] != null) {
          if (count > 0) {
            sql.append(", ");
          }
          sql.append(columns[i].realName);
          count++;
        }
      }
      //
      // Create new values list
      //
      sql.append(") VALUES(");
      count = 0;
      for (int i = 0; i < columnCount; i++) {
        if (insertRow[i] != null) {
          if (count > 0) {
            sql.append(", ");
          }
          sql.append("?");
          insertRow[i].markerPos = sql.length() - 1;
          params.add(insertRow[i]);
          count++;
        }
      }
      sql.append(')');
      if (count == 0) {
        // Empty insert
        sql.setLength(sqlLen);
        sql.append(" DEFAULT VALUES");
      }
      ParamInfo parameters[] = (ParamInfo[]) params.toArray(new ParamInfo[params.size()]);
      //
      // execute the insert statement
      //
      updateTds.executeSQL(
          sql.toString(),
          null,
          parameters,
          false,
          0,
          statement.getMaxRows(),
          statement.getMaxFieldSize(),
          true);
      int updateCount = 0;
      while (!updateTds.isEndOfResponse()) {
        if (!updateTds.getMoreResults()) {
          if (updateTds.isUpdateCount()) {
            updateCount = updateTds.getUpdateCount();
          }
        }
      }
      updateTds.clearResponseQueue();
      statement.getMessages().checkErrors();
      if (updateCount < 1) {
        // No Insert. Probably will not get here as duplicate key etc
        // will have already been reported as an exception.
        throw new SQLException(Messages.get("error.resultset.insertfail"), "24000");
      }
    }
    //
    if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE
        || resultSetType == ResultSet.TYPE_FORWARD_ONLY && cursorName == null) {
      //
      // Now insert copy of row into result set buffer
      //
      ConnectionJDBC2 con = (ConnectionJDBC2) statement.getConnection();
      Object row[] = newRow();
      for (int i = 0; i < insertRow.length; i++) {
        if (insertRow[i] != null) {
          row[i] = Support.convert(con, insertRow[i].value, columns[i].jdbcType, con.getCharset());
        }
      }
      rowData.add(row);
    }
    rowsInResult++;
    initialRowCnt++;
    //
    // Clear row data
    //
    for (int i = 0; insertRow != null && i < insertRow.length; i++) {
      if (insertRow[i] != null) {
        insertRow[i].clearInValue();
      }
    }
  }
  public void updateRow() throws SQLException {
    checkOpen();
    checkUpdateable();

    rowUpdated = false;
    rowDeleted = false;
    if (currentRow == null) {
      throw new SQLException(Messages.get("error.resultset.norow"), "24000");
    }

    if (onInsertRow) {
      throw new SQLException(Messages.get("error.resultset.insrow"), "24000");
    }

    if (updateRow == null) {
      // Nothing to update
      return;
    }
    boolean keysChanged = false;
    //
    // Construct an SQL UPDATE statement
    //
    StringBuffer sql = new StringBuffer(128);
    ArrayList params = new ArrayList();
    sql.append("UPDATE ");
    sql.append(tableName);
    //
    // OK now create assign new values
    //
    sql.append(" SET ");
    int count = 0;
    for (int i = 0; i < columnCount; i++) {
      if (updateRow[i] != null) {
        if (count > 0) {
          sql.append(", ");
        }
        sql.append(columns[i].realName);
        sql.append("=?");
        updateRow[i].markerPos = sql.length() - 1;
        params.add(updateRow[i]);
        count++;
        if (columns[i].isKey) {
          // Key is changing so in memory row will need to be deleted
          // and reinserted at end of row buffer.
          keysChanged = true;
        }
      }
    }
    if (count == 0) {
      // There are no columns to update in this table
      // so bail out now.
      return;
    }
    //
    // Now construct where clause
    //
    ParamInfo parameters[] = buildWhereClause(sql, params, false);
    //
    // Now execute update
    //
    updateTds.executeSQL(
        sql.toString(),
        null,
        parameters,
        false,
        0,
        statement.getMaxRows(),
        statement.getMaxFieldSize(),
        true);
    int updateCount = 0;
    while (!updateTds.isEndOfResponse()) {
      if (!updateTds.getMoreResults()) {
        if (updateTds.isUpdateCount()) {
          updateCount = updateTds.getUpdateCount();
        }
      }
    }
    updateTds.clearResponseQueue();
    statement.getMessages().checkErrors();

    if (updateCount == 0) {
      // No update. Possibly row was changed on database by another user?
      throw new SQLException(Messages.get("error.resultset.updatefail"), "24000");
    }
    //
    // Update local copy of data
    //
    if (resultSetType != ResultSet.TYPE_SCROLL_INSENSITIVE) {
      // Make in memory copy reflect database update
      // Could use refreshRow but this is much faster.
      ConnectionJDBC2 con = (ConnectionJDBC2) statement.getConnection();
      for (int i = 0; i < updateRow.length; i++) {
        if (updateRow[i] != null) {
          currentRow[i] =
              Support.convert(con, updateRow[i].value, columns[i].jdbcType, con.getCharset());
        }
      }
    }
    //
    // Update state of cached row data
    //
    if (keysChanged && resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE) {
      // Leave hole at current position and add updated row to end of set
      rowData.add(currentRow);
      rowsInResult = rowData.size();
      rowData.set(pos - 1, null);
      currentRow = null;
      rowDeleted = true;
    } else {
      rowUpdated = true;
    }
    //
    // Clear update values
    //
    cancelRowUpdates();
  }