I'm dealing with an Oracle 10g database and the following stored procedure is provided:
procedure get_synopsis (
p_id in my_schema.products.p_id%type,
p_synopses out sys_refcursor); -- cursor of - synopsis_type, synopsis_text
In my Java code I prepare the statement in this way:
String idForDb = fromIdUrlToIdDb(prodIdUrl);
statement.registerOutParameter(1, OracleTypes.VARCHAR);
statement.setString(1, idForDb );
statement.registerOutParameter(2, OracleTypes.CURSOR);
And I get the data I need in this way:
String defaultSyn, nonDefSyn;
String returnedId = ((OracleCallableStatement)stm).getString(1);
try ( ResultSet synopses = ((OracleCallableStatement)stm).getCursor(2) ){ // p_synopses - cursor of: synopsis_type, synopsis_text
while( synopses!=null && synopses.next() ){
String type = synopses.getString(1) != null ? synopses.getString(1).toUpperCase() : null;
if( type != null ){
StringBuilder sb = new StringBuilder();
BufferedReader br = new BufferedReader( synopses.getClob(2).getCharacterStream() );
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
if("DEFAULT".equals(type)){
defaultSyn = sb.toString();
}else if("NONDEFAULT".equals(type)){
nonDefSyn = sb.toString();
}
// ...
}
}
}
The SYNOPSIS_TEXT field is an NCLOB but I use a String for its content since I know for sure that it won't be longer than MAX_INTEGER. The "National character set" used is Unicode.
In the JSON generated from that string I can see correctly handled characters like comma, hypen, dash, single quote, dot, parenthesis, colon, etc but I have problems with special characters like left single quote mark / U+2018 ( ‘ ’ ), that is not correctly displayed. Also I can see in the text new line characters ( \n ) and quotes ( \" ).
Is it correct to return a text in such format to consumers or should I handle it better/differently?