private void testUnsupportedOperations() throws Exception {
    Connection conn = getConnection();
    stat = conn.createStatement();
    stat.execute("create table test(id int, c clob, b blob)");
    stat.execute("insert into test values(1, 'x', x'00')");
    ResultSet rs = stat.executeQuery("select * from test order by id");
    rs.next();
    Clob clob = rs.getClob(2);
    byte[] data = IOUtils.readBytesAndClose(clob.getAsciiStream(), -1);
    assertEquals("x", new String(data, "UTF-8"));
    assertTrue(clob.toString().endsWith("'x'"));
    clob.free();
    assertTrue(clob.toString().endsWith("null"));

    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, clob).truncate(0);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, clob).setAsciiStream(1);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, clob).setString(1, "", 0, 1);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, clob).position("", 0);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, clob).position((Clob) null, 0);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, clob).getCharacterStream(1, 1);

    Blob blob = rs.getBlob(3);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, blob).truncate(0);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, blob).setBytes(1, new byte[0], 0, 0);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, blob).position(new byte[1], 0);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, blob).position((Blob) null, 0);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, blob).getBinaryStream(1, 1);
    assertTrue(blob.toString().endsWith("X'00'"));
    blob.free();
    assertTrue(blob.toString().endsWith("null"));

    stat.execute("drop table test");
    conn.close();
  }
Example #2
0
  public void testConnection() throws SQLException, IOException, ClassNotFoundException {
    mysql();

    DDWell well = new DDWell();
    XStream stream = new XStream(new DomDriver());
    wellBlob = connection.createBlob();
    wellBlob.setBytes(0, new byte[well.toString().length()]);
    wellBlob.setBinaryStream(well.toString().length());
    // Writer clobWriter = wellClob.setCharacterStream(
    // Clob wellClob = connection.createClob();1);
    // clob clobWriter.write(stream.toXML(well));
    // DDWell well2 = (DDWell)stream.fromXML(clobWriter.setCharacterStream());
    // System.out.println(well2);
    String wellBlobString = wellBlob.toString();
    Blob wellBlob2 = new SerialBlob((SerialBlob) stream.fromXML(wellBlobString));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // System.out.println(baos = wellBlob2);
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(wellBlob);
    statement.execute("INSERT INTO well(wellBlob) VALUES('" + oos + "')");
    byte[] employeeAsBytes = baos.toByteArray();
    // ByteArrayInputStream bais = new ByteArrayInputStream(employeeAsBytes);
    // pstmt.setBinaryStream(1, bais, employeeAsBytes.length);
    // pstmt.executeUpdate();
    // pstmt.close();
    ResultSet resultSet = statement.executeQuery("SELECT wellBlob FROM well WHERE ID = 6");
    resultSet.first();
    System.out.println(resultSet.getBlob(1).toString());
    while (resultSet.next()) {
      byte[] st = (byte[]) resultSet.getObject(1);
      ByteArrayInputStream baip = new ByteArrayInputStream(st);
      System.out.println("baip " + baip);
      ObjectInputStream ois = new ObjectInputStream(baip);
      System.out.println("ois " + ois);
      // well well2 = (DDWell) ois.readObject();
      System.out.println("4");
      // System.out.println("well " + well.toString() + " well2 " + well2.toString());
    }
  }