Package java.sql

Examples of java.sql.Blob


                    try
                    {
                        if (rs.next())
                        {
                            String type = rs.getString(1);
                            Blob blob = rs.getBlob(2);
                            String attributes = null;
                            if (blob != null)
                            {
                                attributes = blobToString(blob);
                            }
View Full Code Here


    {
        int nullCount = 0;
        int rowCount = 0;
        byte[] buff = new byte[128];
        // fetch row back, get the long varbinary column as a blob.
        Blob blob;
        int blobLength = 0, i = 0;
        while (rs.next()) {
            i++;
            // get the first column as a clob
            blob = rs.getBlob(1);
            long crc32 = rs.getLong(3);
            boolean crc2Null = rs.wasNull();
            if (blob == null) {
                if (!crc2Null)
                    System.out.println("FAIL: NULL BLOB but non-NULL checksum");
                nullCount++;
                continue;
            }
           
            rowCount++;
           
            long blobcrc32 = getStreamCheckSum(blob.getBinaryStream());
           
            if (blobcrc32 != crc32) {
                System.out.println("FAIL: mismatched checksums for blob with length " +
                        blob.length());
            }
           
           
            InputStream fin = blob.getBinaryStream();
            int columnSize = 0;
            for (;;) {
                int size = fin.read(buff);
                if (size == -1)
                    break;
                columnSize += size;
            }
            blobLength = rs.getInt(2);
            if (columnSize != blobLength)
                System.out.println("test failed, columnSize should be " + blobLength
                   + ", but it is " + columnSize + ", i = " + i);
            if (columnSize != blob.length())
                System.out.println("test failed, blob.length() should be " +  columnSize
                   + ", but it is " + blob.length() + ", i = " + i);
        }
        System.out.println("Row Count " + rowCount + " Null Row " + nullCount);
    }
View Full Code Here

    try
        {
      stmt = conn.createStatement();
      rs = stmt.executeQuery("select a,b from testBlob");
            int i = 0, blobLength = 0;
            Blob blob;
      while (rs.next())
            {
                i++;
                blob = rs.getBlob(1);
                if (blob == null)
                    continue;
                blobLength = rs.getInt(2);
                blobclob4BLOB.printInterval(blob, 9905, 50, 0, i, blobLength);
                blobclob4BLOB.printInterval(blob, 5910, 150, 1, i, blobLength);
                blobclob4BLOB.printInterval(blob, 5910, 50, 2, i, blobLength);
                blobclob4BLOB.printInterval(blob, 204, 50, 3, i, blobLength);
                blobclob4BLOB.printInterval(blob, 68, 50, 4, i, blobLength);
                blobclob4BLOB.printInterval(blob, 1, 50, 5, i, blobLength);
                blobclob4BLOB.printInterval(blob, 1, 1, 6, i, blobLength);
                blobclob4BLOB.printInterval(
                        blob, 1, 0, 7, i, blobLength); // length 0 at start
                blobclob4BLOB.printInterval(
                        blob, blobLength + 1, 0, 8, i, blobLength); // and end
                /*
                System.out.println(i + "(0) " + new String(blob.getBytes(9905,50), "US-ASCII"));
                System.out.println(i + "(1) " + new String(blob.getBytes(5910,150), "US-ASCII"));
                System.out.println(i + "(2) " + new String(blob.getBytes(5910,50), "US-ASCII"));
                System.out.println(i + "(3) " + new String(blob.getBytes(204,50), "US-ASCII"));
                System.out.println(i + "(4) " + new String(blob.getBytes(68,50), "US-ASCII"));
                System.out.println(i + "(5) " + new String(blob.getBytes(1,50), "US-ASCII"));
                System.out.println(i + "(6) " + new String(blob.getBytes(1,1), "US-ASCII"));
                */
                if (blobLength > 100)
                {
                    byte[] res = blob.getBytes(blobLength-99,200);
                    System.out.println(i + "(9) ");
                    if (res.length != 100)
                        System.out.println("FAIL : length of bytes is " +
                            res.length + " should be 100");
                    else
View Full Code Here

    try
        {
      stmt = conn.createStatement();
      rs = stmt.executeQuery("select a,b from testBlob");
            int i = 0, blobLength = 0;
            Blob blob;
      while (rs.next())
            {
                i++;
                blob = rs.getBlob(1);
                if (blob == null)
View Full Code Here

    try
        {
      stmt = conn.createStatement();
      rs = stmt.executeQuery("select a,b from testBlob");
            int i = 0, blobLength = 0;
            Blob blob;
      while (rs.next())
            {
                i++;
                blob = rs.getBlob(1);
                if (blob == null)
                    continue;
                blobLength = rs.getInt(2);
                if (blobLength > 20000)
                    {
                        System.out.println("testBlob row " + i + " skipped (too large)");
                        continue;
                    }
                // inner loop over table of blobs to search for
                // blobs
          stmt2 = conn.createStatement();
          rs2 = stmt2.executeQuery("select a,b from searchBlob");
                int j = 0, blobLength2 = 0;
                Blob searchBlob;
                String searchStr;
          while (rs2.next())
                {
                    j++;
                    searchBlob = rs2.getBlob(1);
View Full Code Here

            int j = 0;
      // fetch all rows back, get the columns as clobs.
      while (rs.next())
            {
        // get the first column as a clob
                Blob blob = rs.getBlob(1);
                if (blob == null)
                    continue;
        InputStream fin = blob.getBinaryStream();
        int columnSize = 0;
        for (;;)
                {
          int size = fin.read(buff);
          if (size == -1)
            break;
          columnSize += size;
        }
                if (columnSize != j)
                    System.out.println("FAIL - Expected blob size : " + j +
                        " Got blob size : " + columnSize);
                if (blob.length() != j)
                    System.out.println("FAIL - Expected blob length : " + j +
                        " Got blob length : " + blob.length());
                j++;
      }
            ps.close();
            stmt.close();
            conn.commit();
View Full Code Here

      ResultSet rs = stmt.executeQuery("select a from testInteger2");
      while (rs.next()) {
        // get the first column as a clob
                try {
                    Blob blob = rs.getBlob(1);
                    System.out.println("FAIL fetched java.sql.Blob from INT column");
                } catch (SQLException e) {
                    TestUtil.dumpSQLExceptions(e,
                            "22005".equals(e.getSQLState()) ||
                            "XCL12".equals(e.getSQLState()));
View Full Code Here

      stmt = conn.createStatement();
      stmt.execute("create table testBlob2 (a integer, b integer)");
            PreparedStatement ps = conn.prepareStatement(
                "insert into testBlob2 values(?,?)");
      rs = stmt.executeQuery("select a,b from testBlob");
            Blob blob;
            int blobLength;
      while (rs.next())
            {
        // get the first column as a blob
                blob = rs.getBlob(1);
View Full Code Here

    try
        {
      stmt = conn.createStatement();
      rs = stmt.executeQuery("select a,b from testBlob");
            int i = 0, blobLength = 0;
            Blob blob;
      while (rs.next())
            {
                if (i > 0)
                    break;
                i++;
                blob = rs.getBlob(1);
                if (blob == null)
                    continue;
                blobLength = rs.getInt(2);
                // test end cases

                // 0 or negative position value
                try
                {
                    blob.getBytes(0,5);
                }
            catch (SQLException e)
                {
              TestUtil.dumpSQLExceptions(e,isOutOfBoundException(e));
            }
                // negative length value
                try
                {
                    blob.getBytes(1,-76);
                }
            catch (SQLException e)
                {
              TestUtil.dumpSQLExceptions(e,isOutOfBoundException(e));
            }
                // zero length value
                try
                {
                    blob.getBytes(1,-1);
                }
            catch (SQLException e)
                {
              TestUtil.dumpSQLExceptions(e,isOutOfBoundException(e));
            }
                // before begin length 0
                try {
                    blob.getBytes(0,0);
                } catch (SQLException e) {
                    TestUtil.dumpSQLExceptions(e,isOutOfBoundException(e));
                }
                // after end length 0
                try {
                    blob.getBytes(blobLength + 2,0);
                } catch (SQLException e) {
                    TestUtil.dumpSQLExceptions(e,isOutOfBoundException(e));
                }
                // 0 or negative position value
                try
                {
                    blob.position(new byte[0],-4000);
                }
            catch (SQLException e)
                {
              TestUtil.dumpSQLExceptions(e,isOutOfBoundException(e));
            }
                // null pattern
                try
                {
          // bug 5247 in network server (NPE)
                    blob.position((byte[]) null,5);
                }
            catch (SQLException e)
                {
              TestUtil.dumpSQLExceptions(e,isNullSearchPattern(e));
            }
                // 0 or negative position value
                try
                {
                    blob.position(blob,-42);
                }
            catch (SQLException e)
                {
              TestUtil.dumpSQLExceptions(e,isOutOfBoundException(e));
            }
                // null pattern
                try
                {
                    blob.position((Blob) null,5);
                }
            catch (SQLException e)
                {
              TestUtil.dumpSQLExceptions(e,isNullSearchPattern(e));
            }
View Full Code Here

      stmt1.execute("create table testBlobX (a blob(300K), b integer)");
            PreparedStatement ps = conn.prepareStatement(
                "insert into testBlobX values(?,?)");
      stmt2 = conn.createStatement();
      rs = stmt2.executeQuery("select a,b from testBlob");
            Blob blob;
            int blobLength;
      while (rs.next())
            {
        // get the first column as a blob
                blob = rs.getBlob(1);
                if (blob == null)
                    continue;
                blobLength = rs.getInt(2);
                ps.setBlob(1,blob);
                ps.setInt(2,blobLength);
                ps.executeUpdate();
      }
            rs.close();
            conn.commit();

      rs2 = stmt2.executeQuery("select a,b from testBlobX");
            Blob blob2;
            int blobLength2, j = 0;
      while (rs2.next())
            {
                j++;
        // get the first column as a clob
                blob2 = rs2.getBlob(1);
                if (blob2 == null)
                    continue;
                blobLength2 = rs2.getInt(2);
                if (blob2.length() != blobLength2)
                    System.out.println("FAILED at row " + j);
      }
            rs2.close();

            stmt1.close();
View Full Code Here

TOP

Related Classes of java.sql.Blob

Copyright © 2018 www.massapicom. 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.