Wednesday, August 31, 2016

Convert Blob to string

public String BlobToString(Blob input) throws Exception{
            byte[] bdata = input.getBytes(1, (int)input.length());
        String data1 = new String(bdata);
        return data1;
    }

How to get big size clob content from table

select column1,DBMS_LOB.SUBSTR(clobColumn,4000,1) as clobColumn 
               from table

Convert Sql clob to string in java

    String query = "";
            ResultSet output = stmt.executeQuery(query);
            String clobStr ="";
            while(output.next()){
                StringBuffer strOut = new StringBuffer();
                String aux;
                try {
                    BufferedReader br = new BufferedReader(output.getClob("").
                            getCharacterStream());
                    while ((aux=br.readLine())!=null) {
                        strOut.append(aux);
                        strOut.append(System.getProperty("line.separator"));
                    }
                }catch (Exception e) {
                    e.printStackTrace();
                }
                clobStr = strOut.toString().replace(" ", "").trim();
            }