I am writing a Java code to read Blob objects from an Oracle database table.
I need to retrieve the blob objects and store them into a String for further processing.
I convert the blob objects contents to String by this :
java.sql.Blob blob = rs.getBlob(i);
columnValue = new String(blob.getBytes(1l, (int) blob.length()));
However when I try to parse the resultant string, I get errors which say “Not a valid escape sequence” because apparently the Blob data consists of some data like \x, \i or something !
Is there a way to make Java ignore these escape sequences and make it to just consider the string with its contents as it is (i.e Strings containing \x, \i etc.) ?
I assume that by “parse” you mean something related to regex, because otherwise storing these values in a string will work fine – the escape sequences are useful only for string literals and regexes.
Anyway,
StringEscapeUtils.escapeJava(..)should do what you want (it’s from commons-lang)Apart from that – you should use
java.sql.Clobfor textual data.