오라클에서 varchar2 자료유형을 아래와 같이 CLOB으로 변경할 경우 ORA-22858: 데이터유형의 변경이 부적당합니다. 에러메시지를 만나게 된다.

ALTER TABLE 대상_테이블명 MODIFY (대상_컬럼명 CLOB); 

해결 방법은 아래와 같다.

/*
* MEMO 칼럼을 varchar2에서 clob으로 바꾸는 경우 샘플
*/

ALTER TABLE 대상_테이블명 ADD MEMO_NEW CLOB;

UPDATE  대상_테이블명 SET MEMO_NEW = MEMO;

COMMIT;

ALTER TABLE  대상_테이블명 DROP COLUMN MEMO;

ALTER TABLE  대상_테이블명 RENAME COLUMN MEMO_NEW TO MEMO;



10g XE에서 잘 돌아가던 넘이 운영서버 환경에 올리자 CLOB 등록이 안된다.

iBatis 단독 사용 시 CLOB 넣기

sqlmap-config.xml

<typeHandler javaType="string" jdbcType="CLOB" callback="test.OracleClobStringTypeHandler"/>
 
<transactionManager type="JDBC">
    <dataSource type="SIMPLE">
        <property name="JDBC.Driver" value="oracle.jdbc.driver.OracleDriver" />
        <property name="JDBC.ConnectionURL" value="jdbc:oracle:thin:@xxxxx:1521:SID" />
        <property name="JDBC.Username" value="${ID}" />
        <property name="JDBC.Password" value="${PASS}" />
    </dataSource>
</transactionManager>

logic-sqlmap.xml

INSERT INTO TABLE_NAME (
    SEQ, TITLE, CONTENTS
)
VALUES(
    #seq#, #title#, #contents:CLOB#
)

iBatis + Spring단독 사용 시 CLOB 넣기

application-context.xml

<bean id="dataSource"
    class="org.springframework.jndi.JndiObjectFactoryBean">
   <property name="jndiName" value="java:comp/env/jdbc/jndiNameDS"/>
</bean>

<bean id="sqlMapClient"
    class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="configLocation" value="WEB-INF/conf/sqlmap-config.xml" />
    <property name="dataSource" ref="dataSource" />
    <property name="lobHandler"><ref bean="oracleLobhandler"/></property>
</bean>

<bean id="nativeJdbcExtractor"
    class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor"
    lazy-init="true" />

<bean id="oracleLobhandler"
    class="org.springframework.jdbc.support.lob.OracleLobHandler"
    lazy-init="true">
    <property name="nativeJdbcExtractor">
        <ref local="nativeJdbcExtractor" />
    </property>
</bean>

sqlmap-config.xml

<typeHandler
    callback="org.springframework.orm.ibatis.support.ClobStringTypeHandler"
    jdbcType="CLOB" javaType="java.lang.String" />

logic-sqlmap.xml

INSERT INTO TABLE_NAME (
    SEQ, TITLE, CONTENTS
)
VALUES(
    #seq#, #title#, #contents:CLOB#
)

java.lang.NullPointerException at org.springframework.jdbc.support.lob.OracleLobHandler.initOracleDriverClasses(OracleLobHandler.java:150
) 에러 발생 시


application-context.xml

JNDI -> DBCP로 변경
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
     <property name="driverClassName" value="oracle.jdbc.OracleDriver" />
     <property name="url" value="jdbc:oracle:thin:@xxxx:1521:SID" />
     <property name="username" value="${ID}" />
     <property name="password" value="${PASS}" />
     <parameter name="maxActive" value="20" />
     <parameter name="maxIdle" value="5" />
     <parameter name="maxWait" value="5000" />
     <property name="validationQuery" value="SELECT 1 FROM DUAL" />
</bean>

Oracle JDBC 드라이버는 ojdbc14.jar (최신버전)으로 적용.

+ Recent posts