Examples of Blob


Examples of java.sql.Blob

        conn = reconnect(conn);
        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST ORDER BY ID");
        while (rs.next()) {
            int i = rs.getInt("ID");
            Blob b = rs.getBlob("B");
            Clob c = rs.getClob("C");
            int l = i;
            assertEquals(l, b.length());
            assertEquals(l, c.length());
            assertEqualStreams(getRandomStream(l, i), b.getBinaryStream(), -1);
            assertEqualReaders(getRandomReader(l, i), c.getCharacterStream(), -1);
        }

        prep = conn.prepareStatement("UPDATE TEST SET B=?, C=? WHERE ID=?");
        for (int i = first; i < len; i += increment) {
            int l = i;
            prep.setBinaryStream(1, getRandomStream(l, -i), -1);
            prep.setCharacterStream(2, getRandomReader(l, -i), -1);
            prep.setInt(3, i);
            prep.execute();
        }

        conn = reconnect(conn);
        rs = conn.createStatement().executeQuery("SELECT * FROM TEST ORDER BY ID");
        while (rs.next()) {
            int i = rs.getInt("ID");
            Blob b = rs.getBlob("B");
            Clob c = rs.getClob("C");
            int l = i;
            assertEquals(l, b.length());
            assertEquals(l, c.length());
            assertEqualStreams(getRandomStream(l, -i), b.getBinaryStream(), -1);
            assertEqualReaders(getRandomReader(l, -i), c.getCharacterStream(), -1);
        }

        conn.close();
    }
View Full Code Here

Examples of java.sql.Blob

    private void testBlob(int length) throws Exception {
        Random r = new Random(length);
        byte[] data = new byte[length];
        r.nextBytes(data);
        Blob b = conn.createBlob();
        OutputStream out = b.setBinaryStream(1);
        out.write(data, 0, data.length);
        out.close();
        stat.execute("delete from test");
        PreparedStatement prep = conn.prepareStatement("insert into test values(?, ?)");
        prep.setInt(1, 1);
        prep.setBlob(2, b);
        prep.execute();
        prep.setInt(1, 2);
        b = conn.createBlob();
        b.setBytes(1, data);
        prep.setBlob(2, b);
        prep.execute();
        ResultSet rs;
        rs = stat.executeQuery("select * from test");
        rs.next();
        Blob b2 = rs.getBlob(2);
        assertEquals(length, b2.length());
        byte[] bytes = b.getBytes(1, length);
        byte[] bytes2 = b2.getBytes(1, length);
        assertEquals(bytes, bytes2);
        rs.next();
        b2 = rs.getBlob(2);
        assertEquals(length, b2.length());
        bytes2 = b2.getBytes(1, length);
        assertEquals(bytes, bytes2);
    }
View Full Code Here

Examples of java.sql.Blob

        } catch (Throwable e) {
          // TODO Auto-generated catch block
          throw new SQLException(e);
        }
          } else if (object instanceof Blob){
                Blob b = (Blob)object;
                try {
                  result = ObjectConverterUtil.convertToString(b.getBinaryStream());
           
          } catch (Throwable e) {
            // TODO Auto-generated catch block
            throw new SQLException(e);
          }
View Full Code Here

Examples of java.sql.Blob

    String string = result.getSubString(1, (int)result.length());
    assertEquals("hello world", string);
  }
 
  @Test public void testToBytes() throws Exception {
    Blob result = (Blob)helpInvokeMethod("to_bytes", new Class<?>[] {DefaultDataClasses.CLOB, DefaultDataClasses.STRING}, new Object[] { new ClobType(new SerialClob("hello world".toCharArray())), "UTF32" }, null); //$NON-NLS-1$
    assertEquals(44, result.length()); //4 bytes / char
  }
View Full Code Here

Examples of java.sql.Blob

    String string = result.getSubString(1, (int)result.length());
    assertEquals("68656C6C6F20776F726C64", string);
  }
 
  @Test public void testToBytes2() throws Exception {
    Blob result = (Blob)helpInvokeMethod("to_bytes", new Class<?>[] {DefaultDataClasses.CLOB, DefaultDataClasses.STRING}, new Object[] { new ClobType(new SerialClob("68656C6C6F20776F726C64".toCharArray())), "HEX" }, null); //$NON-NLS-1$
    assertEquals("hello world", new String(ObjectConverterUtil.convertToCharArray(result.getBinaryStream(), -1, "ASCII")));
  }
View Full Code Here

Examples of java.sql.Blob

            } catch (Throwable e) {
              // TODO Auto-generated catch block
              throw new QueryTestFailedException(e);
            }
                  } else if (actualValue instanceof Blob){
                        Blob b = (Blob)actualValue;
                        try {
                  actualValue = ObjectConverterUtil.convertToString(b.getBinaryStream());
                 
                } catch (Throwable e) {
                  // TODO Auto-generated catch block
                  throw new QueryTestFailedException(e);
                }
View Full Code Here

Examples of java.sql.Blob

    }
    else if (o instanceof Blob)
    {
      try
      {
        final Blob b = (Blob) o;
        final byte[] data = b.getBytes(1, (int) b.length());
        final ResourceManager resManager = runtime.getProcessingContext().getResourceManager();
        final Resource resource = resManager.createDirectly(data, DrawableWrapper.class);
        return resource.getResource();
      }
      catch (Exception e)
View Full Code Here

Examples of java.sql.Blob

    }
    else if (o instanceof Blob)
    {
      try
      {
        final Blob b = (Blob) o;
        final byte[] data = IOUtils.getInstance().readBlob(b);
        final ResourceManager resManager = runtime.getProcessingContext().getResourceManager();
        final Resource resource = resManager.createDirectly(data, Image.class);
        return new DefaultImageReference(resource);
      }
View Full Code Here

Examples of java.sql.Blob

            return Any.NULL;
          }
        }

      case Types.BLOB:
        Blob blob = set.getBlob(field);
        if (blob != null) {
          return new AnyString(new String(blob.getBytes(0, (int)blob.length())));
        } else {
          return Any.NULL;
        }

      case Types.CLOB:
View Full Code Here

Examples of java.sql.Blob

            return Any.NULL;
          }
        }

      case Types.BLOB:
        Blob blob = stmt.getBlob(field);
        if (blob != null) {
          return new AnyString(new String(blob.getBytes(0, (int)blob.length())));
        } else {
          return Any.NULL;
        }

      case Types.CLOB:
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.