Package java.sql

Examples of java.sql.Blob


    try
        {
      stmt = conn.createStatement();
      rs = stmt.executeQuery("select a,b from testBlob");
      // fetch row back, get the column as a blob.
            Blob blob = null, shortBlob = null;
            int blobLength;
      while (rs.next())
            {
                blobLength = rs.getInt(2);
                if (blobLength == 10000)
View Full Code Here


            fileIn.close();
            conn.commit();

      stmt = conn.createStatement();
      rs = stmt.executeQuery("select e from testLongRowBlob");
            Blob blob = null;
      while (rs.next()) {
                blob = rs.getBlob(1);
                checkBlobAgainstFile(1, blob);
           }
            rs.close();
View Full Code Here

        try
        {
      stmt = conn.createStatement();
      rs = stmt.executeQuery("select a,b from testBlob");
      // fetch row back, get the column as a blob.
            Blob blob = null, shortBlob = null;
            int blobLength;
      while (rs.next())
            {
                blobLength = rs.getInt(2);
                if (blobLength == 10000)
                    blob = rs.getBlob(1);
                if (blobLength == 26)
                    shortBlob = rs.getBlob(1);
      }
            rs.close();
            conn.commit();

            // no problem accessing this after commit since it is in memory
            if (shortBlob != null)
            System.out.println("shortBlob length after commit is " + shortBlob.length());
            // these should all give blob/clob data unavailable exceptions

            try
            {
                blob.length();
            }
            catch (SQLException e)
            {
          TestUtil.dumpSQLExceptions(e);
        }
            try
            {
                blob.getBytes(2,3);
            }
            catch (SQLException e)
            {
          TestUtil.dumpSQLExceptions(e);
        }
            try
            {
                blob.getBinaryStream();
            }
            catch (SQLException e)
            {
          TestUtil.dumpSQLExceptions(e);
        }
            try
            {
                blob.position("foo".getBytes("US-ASCII"),2);
            }
            catch (SQLException e)
            {
          TestUtil.dumpSQLExceptions(e);
        }
            try
            {
                blob.position(blob,2);
            }
            catch (SQLException e)
            {
          TestUtil.dumpSQLExceptions(e);
        }
View Full Code Here

        try
        {
      stmt = conn.createStatement();
      rs = stmt.executeQuery("select a,b from testBlob");
      // fetch row back, get the column as a blob.
            Blob blob = null, shortBlob = null;
            int blobLength;
      while (rs.next())
            {
                blobLength = rs.getInt(2);
                if (blobLength == 10000)
                    blob = rs.getBlob(1);
                if (blobLength == 26)
                    shortBlob = rs.getBlob(1);
      }
            rs.close();
      conn.rollback();
            conn.close();

      try {
        // no problem accessing this after commit since it is in memory
        System.out.println("shortBlob length after closing the connection is " + shortBlob.length());
      }
      catch (SQLException e)
      {
        expectedExceptionForNSOnly (e);
      }

        // these should all give blob/clob data unavailable exceptions
            try
            {
                blob.length();
            }
            catch (SQLException e)
            {
        expectedExceptionForNSOnly (e);
        }
            try
            {
                blob.getBytes(2,3);
            }
            catch (SQLException e)
            {
        expectedExceptionForNSOnly (e);
        }
            try
            {
                blob.getBinaryStream();
            }
            catch (SQLException e)
            {
        expectedExceptionForNSOnly (e);
        }
            try
            {
                blob.position("foo".getBytes("US-ASCII"),2);
            }
            catch (SQLException e)
            {
        expectedExceptionForNSOnly (e);
        }
            try
            {
                blob.position(blob,2);
            }
            catch (SQLException e)
            {
        expectedExceptionForNSOnly (e);
        }
View Full Code Here

    }

    private static void checkContentsBeforeAndAfterUpdatingBlob(ResultSet rs)
            throws SQLException
    {
        Blob b;
        byte[] value, expectedValue;
        String blobData = "initial blob ";
        String updatedBlobData = "updated blob ";
       
        b = rs.getBlob(2);
        // check contents
        value = b.getBytes(1, blobData.length() + 1);
        expectedValue = (blobData + rs.getInt(1)).getBytes();
        if (!Arrays.equals(value, expectedValue)) {
            System.out.println("blobTest10 - Error: wrong blob value");
        }

        // update contents
        value = (updatedBlobData + rs.getInt(1)).getBytes();
        rs.updateBytes(2, value);
        rs.updateRow();
        // check update values
        rs.next(); // leave the row
        rs.previous(); // go back to updated row
        b = rs.getBlob(2);
        // check contents
        value = b.getBytes(1, updatedBlobData.length() + 1);
        expectedValue = (updatedBlobData + rs.getInt(1)).getBytes();
        if (!Arrays.equals(value, expectedValue))
        {
            System.out.println("blobTest10 - Error: wrong blob value");
        }
View Full Code Here

    }

    private static void updateBlobWithUpdateBinaryStream(ResultSet rs)
            throws SQLException
    {
        Blob b;
        byte[] value, expectedValue;
        String blobData = "initial blob ";
        String updatedBlobData = "updated blob ";
       
        b = rs.getBlob(2);
        // check contents
        value = b.getBytes(1, blobData.length() + 1);
        expectedValue = (blobData + rs.getInt(1)).getBytes();
        if (!Arrays.equals(value, expectedValue)) {
            System.out.println("blobTest11 - Error: wrong blob value");
        }

        // update contents
        value = (updatedBlobData + rs.getInt(1)).getBytes();
        InputStream updateValue = new ByteArrayInputStream(value);
        rs.updateBinaryStream(2, updateValue, value.length);
        rs.updateRow();
        // check update values
        rs.next(); // leave the row
        rs.previous(); // go back to updated row
        b = rs.getBlob(2);
        // check contents
        value = b.getBytes(1, updatedBlobData.length() + 1);
        expectedValue = (updatedBlobData + rs.getInt(1)).getBytes();
        if (!Arrays.equals(value, expectedValue))
        {
            System.out.println("blobTest11 - Error: wrong blob value");
        }
View Full Code Here

                ResultSet.CONCUR_READ_ONLY);
        s2.executeQuery("SELECT \"MAP_ID\", \"MAP_NAME\", \"REGION\", \"AREA\", \"PHOTO_FORMAT\", \"PICTURE\" FROM \"MAPS_BLOB\"");
        ResultSet rs2 = s2.getResultSet();
        rs2.next();

        Blob b2 = rs2.getBlob(6);
        rs1.next();
        Blob b1 = rs1.getBlob(6);
        try {
            rs1.close();
            rs2.next();
            rs2.getBlob(6);
        } catch (SQLException sqle) {
View Full Code Here

        if (useGetBytesForBlobs || useGetObjectForBlobs) {
            byte[] bytes = getBytes(rs, column);
            if (bytes != null && bytes.length > 0)
                in = new ByteArrayInputStream(bytes);
        } else {
            Blob blob = getBlob(rs, column);
            if (blob != null && blob.length() > 0)
                in = blob.getBinaryStream();
        }
        if (in == null)
            return null;

        try {
View Full Code Here

        if (useGetBytesForBlobs)
            return rs.getBytes(column);
        if (useGetObjectForBlobs)
            return (byte[]) rs.getObject(column);

        Blob blob = getBlob(rs, column);
        if (blob == null)
            return null;
        int length = (int) blob.length();
        if (length == 0)
            return null;
        return blob.getBytes(1, length);
    }
View Full Code Here

                ResultSet.CONCUR_UPDATABLE);
            res = stmnt.executeQuery();
            if (!res.next()) {
                throw new InternalException(_loc.get("stream-exception"));
            }
            Blob blob = res.getBlob(1);
            OutputStream os = blob.setBinaryStream(1);
            copy(is, os);
            os.close();
            res.updateBlob(1, blob);
            res.updateRow();
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.