Wednesday, March 20, 2013

How to convert from Sql Blob to String in Java

            Blob blob=rset.getBlob("content");

            int blobLength = (int) blob.length(); 

            byte[] blobAsBytes = blob.getBytes(1, blobLength);

            ByteArrayInputStream bo = new ByteArrayInputStream(blobAsBytes);

            ObjectInputStream bis = new ObjectInputStream(bo);
           
            Map map = (Map)bis.readObject();

            String category=map.toString();