Special characters in Oracle NCLOB

北慕城南 提交于 2019-12-02 11:29:56

问题


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?

来源:https://stackoverflow.com/questions/36393449/special-characters-in-oracle-nclob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!