http://cafe.naver.com/deve/1046

public class OracleCLOBTypeHandler implements TypeHandlerCallback {

    public void setParameter(ParameterSetter setter, Object paramthrows SQLException {

        try {
            setter.setClob((Clobparam);
        catch (SQLException e) {
            if (log.isErrorEnabled())
                log.error("Failed to set CLOB parameter");
            throw e;
        }
    }


    public Object getResult(ResultGetter getterthrows SQLException {

        Clob clob = null;
        try {
            clob = getter.getClob();
        catch (SQLException e) {
            if (log.isErrorEnabled())
                log.error("Failed to set CLOB result property");
            throw e;
        }

        return clob;
    }

    public Object valueOf(String arg0) {

        return arg0;
    }

}

====> SQLMap (essay 빈의 content 속성이 CLOB 타입으로 정하고...)

<resultMap id="xmlRslt" class="essay">
    <result property="content" column="content" typeHandler="OracleCLOBTypeHandler"/>
</resultMap>

<statement id="getXMLData" resultMap="xmlRslt">
    select content from essay
</statement>

====> CLOB의 데이터를 문자열로 변환하는 메소드.

public static String getStringForCLOB(CLOB clob) {
        String str = "";
        StringBuffer sbf = new StringBuffer();
        Reader br = null;
        char[] buf = new char[1024];
        int readcnt;

        try {
            br = clob.getCharacterStream(0L);

            while ((readcnt=br.read(buf,0,1024))!=-1) {
                sbf.append(buf,0,readcnt);
            }

        catch (Exception e) {
            if (log.isErrorEnabled())
                 log.error("Failed to create String object from CLOB", e);

        }finally{
            if(br!=null)
                try {
                    br.close();
                catch (IOException e) {
                    if (log.isErrorEnabled())
                        log.error("Failed to close BufferedReader object", e);

               }
        }
        return sbf.toString();
    

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-2) was last changed on 14-Mar-2007 18:09 by 58.230.205.70