示例#1
0
  private static void callGetMethod(
      CallableStatement cs, int arg, int type, int paramType, StringBuilder strbuf)
      throws Throwable {
    switch (type) {
      case Types.BIT:
      case Types.BOOLEAN:
        strbuf.append("getBoolean(" + arg + ") = ");
        strbuf.append(cs.getBoolean(arg));
        break;

      case Types.TINYINT:
        strbuf.append("getByte(" + arg + ") = ");
        strbuf.append(Byte.toString(cs.getByte(arg)));
        break;

      case Types.SMALLINT:
        strbuf.append("getShort(" + arg + ") = ");
        strbuf.append(Short.toString(cs.getShort(arg)));
        break;

      case Types.INTEGER:
        strbuf.append("getInt(" + arg + ") = ");
        strbuf.append(Integer.toString(cs.getInt(arg)));
        break;

      case Types.BIGINT:
        strbuf.append("getLong(" + arg + ") = ");
        strbuf.append(Long.toString(cs.getLong(arg)));
        break;

      case Types.FLOAT:
      case Types.REAL:
        strbuf.append("getFloat(" + arg + ") = ");
        strbuf.append(Float.toString(cs.getFloat(arg)));
        break;

      case Types.DOUBLE:
        strbuf.append("getDouble(" + arg + ") = ");
        strbuf.append(Double.toString(cs.getDouble(arg)));
        break;

      case Types.DECIMAL:
      case Types.NUMERIC:
        strbuf.append("getBigDecimal(" + arg + ") = ");
        strbuf.append(BigDecimalHandler.getBigDecimalString(cs, arg, paramType));
        break;

      case Types.CHAR:
      case Types.VARCHAR:
      case Types.LONGVARCHAR:
        strbuf.append("getString(" + arg + ") = ");
        String s = cs.getString(arg);
        if (s.startsWith("[B@")) s = "byte[] reference";
        strbuf.append(s);
        break;

      case Types.BINARY:
      case Types.VARBINARY:
      case Types.LONGVARBINARY:
        strbuf.append("getBytes(" + arg + ") = ");
        byteArrayToString(cs.getBytes(arg), strbuf);
        break;

      case Types.DATE:
        strbuf.append("getDate(" + arg + ") = ");
        Date date = cs.getDate(arg);
        strbuf.append(date == null ? "null" : date.toString());
        break;

      case Types.TIME:
        strbuf.append("getTime(" + arg + ") = ");
        Time time = cs.getTime(arg);
        strbuf.append(time == null ? "null" : time.toString());
        break;

      case Types.TIMESTAMP:
        strbuf.append("getTimestamp(" + arg + ") = ");
        Timestamp timestamp = cs.getTimestamp(arg);
        strbuf.append(timestamp == null ? "null" : timestamp.toString());
        break;

      case Types.OTHER:
        strbuf.append("getObject(" + arg + ") = ");
        Object o = cs.getObject(arg);
        if (o == null) {
          strbuf.append("null");
        } else if (o instanceof byte[]) {
          byteArrayToString((byte[]) o, strbuf);
        } else {
          strbuf.append(o.toString());
        }

        break;

      default:
        throw new Throwable("TEST ERROR: unexpected type " + type);
    }
  }
示例#2
0
  private static void callSetMethod(CallableStatement cs, int arg, int type, StringBuilder strbuf)
      throws Throwable {
    switch (type) {
      case Types.BIT:
      case Types.BOOLEAN:
        strbuf.append("setBoolean(" + arg + ", true)");
        cs.setBoolean(arg, true);
        break;

      case Types.TINYINT:
        strbuf.append("setByte(" + arg + ", 6)");
        cs.setByte(arg, (byte) 6);
        break;

      case Types.SMALLINT:
        strbuf.append("setShort(" + arg + ", 66)");
        cs.setShort(arg, (short) 66);
        break;

      case Types.INTEGER:
        strbuf.append("setInt(" + arg + ", 666)");
        cs.setInt(arg, 666);
        break;

      case Types.BIGINT:
        strbuf.append("setLong(" + arg + ", 666)");
        cs.setLong(arg, 666);
        break;

      case Types.FLOAT:
      case Types.REAL:
        strbuf.append("setFLoat(" + arg + ", 666)");
        cs.setFloat(arg, 666);
        break;

      case Types.DOUBLE:
        strbuf.append("setDouble(" + arg + ", 666)");
        cs.setDouble(arg, 666);
        break;

      case Types.DECIMAL:
      case Types.NUMERIC:
        strbuf.append("setBigDecimal(" + arg + ", 666.666)");
        BigDecimalHandler.setBigDecimalString(cs, arg, "666.666");
        break;

      case Types.CHAR:
      case Types.VARCHAR:
      case Types.LONGVARCHAR:
        strbuf.append("setString(" + arg + ", \"Set via setString()\")");
        cs.setString(arg, "Set via setString()");
        break;

      case Types.BINARY:
      case Types.VARBINARY:
      case Types.LONGVARBINARY:
        strbuf.append("setBytes(" + arg + ", byte[])");
        byte[] myarray = new byte[16];
        myarray[0] = (byte) 255;
        cs.setBytes(arg, myarray);
        break;

      case Types.DATE:
        strbuf.append("setDate(" + arg + ", Date.valueOf(1999-09-09))");
        cs.setDate(arg, Date.valueOf("1999-09-09"));
        break;

      case Types.TIME:
        strbuf.append("setTime(" + arg + ", Time.valueOf(09:09:09))");
        cs.setTime(arg, Time.valueOf("09:09:09"));
        break;

      case Types.TIMESTAMP:
        strbuf.append("setTimestamp(" + arg + ", Timestamp.valueOf(1999-09-09 09:09:09.999))");
        cs.setTimestamp(arg, Timestamp.valueOf("1999-09-09 09:09:09.999"));
        break;

      case Types.OTHER:
        strbuf.append("setObject(" + arg + ", new BigInteger(666))");
        cs.setObject(arg, new BigInteger("666"));
        break;

      default:
        throw new Throwable("TEST ERROR: unexpected type " + type);
    }
  }