Jakarta common-dbcp + oracle9i 사용시

[작렬허접코딩/자바]
문제점이 있다.

common-dbcp + 오라클 9i 이상을 함께 사용할 때 Oracle의 CLOB 컬럼을 읽어올 때 문제가 발생한다.
에러 내용은 다음과 같다.

org.apache.tomcat.dbcp.dbcp.DelegatingResultSet
        at kr.co.jinjin.jjxweb.sql.DBActor.getCLOB(Unknown Source)
        at kr.co.jinjin.jjxweb.BaseJob.readClob(Unknown Source)
        at kr.co.jinjin.jjxweb.Job.doAct(Unknown Source)
        at kr.co.jinjin.servlet.jjxwebservlet.doPost(Unknown Source)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)
        at java.lang.Thread.run(Thread.java:595)

다음은 8i에서 CLOB를 읽어오기 위해 처리하던 부분이다.
public String getCLOB(String poolName,
   String tableName,
   String clobColumnName,
   String sqlstr) throws Exception {
 
  Connection con = null;
  Statement stmt = null;
  ResultSet rs = null;
  Reader m_reader = null;
  char[] m_buffer = null;
 
  StringBuffer readedStr = null;
  StringBuffer qry = new StringBuffer();
 
  qry.append("SELECT " + clobColumnName + " FROM " + tableName);
  qry.append((!sqlstr.trim().toUpperCase().startsWith("WHERE") ? " WHERE " : " ") + sqlstr);
 
  try {
   con = dbcon.getPooledConnection(poolName);
   stmt = con.createStatement();
   rs = stmt.executeQuery(qry.toString());
   
   if(rs.next()) {
    // 문제 발생시키는 놈 Class Casting이 안된다.
    CLOB clob = ((OracleResultSet)rs).getCLOB(clobColumnName);
   
    m_reader = clob.getCharacterStream();
    readedStr = new StringBuffer();
    m_buffer = new char[BUFFER_LENGTH];
   
    int readedIndex = 0;
    while ((readedIndex = m_reader.read(m_buffer)) != -1)  {
     for (int i=0; i<readedIndex; i++) {
      //System.out.print(buffer[i]);
      readedStr.append(new String(m_buffer, 0, readedIndex));
      m_buffer = new char[BUFFER_LENGTH];
     }
    }
   }
   
  } catch(Exception e) {
   throw new Exception("[Exception] DBActor.getCLOB()  : [" + tableName + "." + clobColumnName + "] " + e.getMessage());
  } finally {
   try {
    dbcon.release(rs, stmt, con);
    if(m_reader != null) m_reader.close();
   } catch(Exception e) {
    e.printStackTrace();
   }
  }
 
  return readedStr.toString();
 }

그럼 어떻게 처리해야 하나?
일반적인 varchar2 컬럼을 읽어오듯이
SELECT NORMAL_COL, CLOB_COL FROM MYTABLE WHERE....
이렇게 읽어오니 모든 데이터가 잘도 읽힌다.
참 환장하겠다.
이올린에 북마크하기(0) 이올린에 추천하기(0)
2008/04/04 22:50 2008/04/04 22:50

이 글의 트랙백 주소 :: http://easyblog.co.kr:81/trackback/142

::: 사람과 사람의 교감! 人터넷의 첫 시작! 댓글을 달아주세요! :::