Background Image
조회 수 54561 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

CLOB 이란?

CUBRID 매뉴얼에는 아래와 같이 나와 있다. 간단하게 설명하면, 사이즈가 데이터를 외부 파일로 저장하기 위한 데이터 타입이다.

ü  문자열 데이터를 DB 외부에 저장하기 위한 타입이다.

ü  CLOB 데이터의 최대 길이는 외부 저장소에서 생성 가능한 파일 크기이다.

ü  CLOB 타입은 SQL 문에서 문자열 타입으로 입출력 값을 표현한다. , CHAR(n), VARCHAR(n), NCHAR(n), NCHAR VARYING(n) 타입과 호환된다. , 명시적 타입 변환만 허용되며, 데이터 길이가 서로 다른 경우에는 최대 길이가 작은 타입에 맞추어 절삭(truncate)된다.

ü  CLOB 타입 값을 문자열 값으로 변환하는 경우, 변환된 데이터는 최대 1GB 넘을 없다. 반대로 문자열을 CLOB 타입으로 변환하는 경우, 변환된 데이터는 CLOB 저장소에서 제공하는 최대 파일 크기를 넘을 없다.

 

SQL JDBC 테스트를 위한 준비

아래와 같은 스키마를 가지는 테이블을 생성하고 임의의 테스트 데이터를 입력한다. 테스트 데이터 입력은 아래의 CLOB TYPE 사용 방법을 참고하여 입력한다.

CREATE TABLE CLOB_TBL( col1 CLOB );

 

SQL문에서 CLOB TYPE 사용 방법

SQL 이용한 CLOB 구문은 일반적으로 아래와 같이 사용된다.

ü  Oracle

INSERT INTO CLOB_TBL VALUES(‘VAL’);

SELECT col1 FROM CLOB_TBL;

ü  CUBRID

INSERT INTO CLOB_TBL VALUES(CHAR_TO_CLOB(‘VAL’));

SELECT CLOB_TO_CHAR(col1) FROM CLOB_TBL;

Oracle 묵시적 타입변환이 되지만 CUBRID 그렇지 않다. 그러므로 CHAR_TO_CLOB 또는 CLOB_TO_CHAR이라는 CUBRID에서 제공하는 함수를 이용하여 String CLOB 타입으로 변경을 해줘야 한다.

 

JDBC 이용한 SELECT 방법

기본적으로 CLOB 데이터는 파일로 저장된 데이터이다. 이러한 데이터를 JDBC드라이브를 통해 가져오기 위해서는 getString, StringBuffer, getClob 이용한 3가지 방법으로 나누어진다.

getString 이용한 방법

getString CUBRID 경우 최대 1G 크기를 받을 있다. 그렇기 때문에 1G이상의 데이터를 getString 이용할 없고 아래의 StringBuffer, getClob 이용해야 한다.

String sql = "SELECT col1 FROM CLOB_TBL";

Statement stmt = null;

ResultSet rs = null;

 

stmt = conn.createStatement();

rs = stmt.executeQuery(sql);

 

while(rs.next()){

       System.out.println("getString = " + rs.getString(1));

}

 

rs.close();

stmt.close();

StringBuffer 이용한 방법

StringBuffer 이용한 방법은 아래와 같다. 일반적으로 Oracle에서 Clob데이터를 출력하는 방법으로 많이 사용된다.

String sql = "SELECT col1 FROM CLOB_TBL";

Statement stmt = null;

ResultSet rs = null;

 

stmt = conn.createStatement();

rs = stmt.executeQuery(sql);

 

while(rs.next()){

       StringBuffer output = new StringBuffer();

       Reader input = rs.getCharacterStream(1);

       char[] buffer = new char[1024];

       int byteRead = 0;

       while ((byteRead = input.read(buffer, 0, 1024 )) != -1){

                    output.append(buffer, 0, byteRead);

       }

       System.out.println("getCharacterStream = " + output.toString());

}

 

rs.close();

stmt.close();

getClob 이용한 방법

getClob 이용한 방법은 아래와 같다. ibatis(mybatis)에서 아래와 같이 Clob 처리하며 CUBRID Oracle에서 모두 동일한 결과를 출력한다.

String sql = "SELECT col1 FROM CLOB_TBL";

Statement stmt = null;

ResultSet rs = null;

 

stmt = conn.createStatement();

rs = stmt.executeQuery(sql);

 

while(rs.next()){

       Clob clob = rs.getClob(1);

       if (clob != null) {

                    int size = (int) clob.length();

                    System.out.println("getClob = " + clob.getSubString(1, size));

       }

}

 

rs.close();

stmt.close();

 

JDBC 이용한 INSERT 방법

Statement SQL 직접 수행 방법

CUBRID Oracle 모두 아래와 같이 수행 가능하다. 하지만, Statement 경우 특정 사이즈 이상이 되면 exception 에러가 발생하기 때문에 대용량 데이터 입력을 위해 BLOB데이터 타입을 이용한다면 PrapareStatement 사용은 필수이다.

Statement stmt = null;

 

String sql = "INSERT INTO CLOB_TBL VALUES('CLOB TEST')";

stmt = conn.createStatement();

stmt.executeUpdate(sql);

stmt.close();

setSting 이용한 방법

getString 동일하게 최대 1G까지의 데이터만 받을 있다. Oracle 경우 getString 이용하여 출력이 가능하지만 CUBRID CHAR_TO_CLOB 함수를 이용하여 묵시적 변환을 해야 데티어 getString 이용한 데이터 입력이 가능하다.

ü  Oracle

PreparedStatement pstmt = null;

String sql = "INSERT INTO CLOB_TBL VALUES(?)";;

 

pstmt = conn.prepareStatement(sql);

pstmt.executeUpdate();

pstmt.close();

ü  CUBRID

PreparedStatement pstmt = null;

String sql = "INSERT INTO CLOB_TBL VALUES(CHAR_TO_CLOB(?))";

 

pstmt = conn.prepareStatement(sql);

pstmt.executeUpdate();

pstmt.close();

setClob(CUBRID), EMPTY_CLOB(Oracle) 이용한 방법

CLOB 이용하여 데이터 입력 방법은 Oracle보다 CUBRID 간단하고 사용하기가 쉽다.

ü  Oracle

PreparedStatement pstmt = null;

String sql = "INSERT INTO CLOB_TBL VALUES(?)";;

 

pstmt = conn.prepareStatement(sql);

conn.setAutoCommit(false);

sql = "INSERT INTO CLOB_TBL VALUES(EMPTY_CLOB());";

pstmt = conn.prepareStatement(sql);

pstmt.executeUpdate();

 

sql = "SELECT col1 FROM CLOB_TBL WHERE ~";

pstmt = conn.prepareStatement(sql);

ResultSet rs = pstmt.executeQuery();

 

if(rs.next()){

        oracle.sql.CLOB clob =  ((OracleResultSet)rs).getCLOB(1);

        Writer writer = clob.getCharacterOutputStream();

        Reader reader = new CharArrayReader("CLOB TEST-PREPARE-SETCLOB".toCharArray());

        char[] buffer = new char[1024];

        int byteRead = 0;

       

        while (( byteRead = reader.read(buffer, 0, 1024)) != -1){

                     writer.write(buffer, 0, byteRead);

        }

}

ü  CUBRID

PreparedStatement pstmt = null;

String sql = "INSERT INTO CLOB_TBL VALUES(?)";;

 

pstmt = conn.prepareStatement(sql);

Clob clob = conn.createClob();

clob.setString(1, "CLOB TEST-PREPARE-SETCLOB");

pstmt.setClob(1, clob);

pstmt.executeUpdate();


  1. CUBRID Migration방법(by unloaddb & loaddb)

    Date2015.07.01 Category기타 By주현 Views21901
    Read More
  2. 콘솔에서 마이그레이션 하기.

    Date2015.06.19 Category기타 By권호일 Views13432
    Read More
  3. CUBRID HA 환경에서 Apache-PHP 설정 가이드

    Date2015.06.16 CategoryPHP By이용미 Views10665
    Read More
  4. CUBRID isolation level & Dirty Read

    Date2015.05.29 Category기타 By정만영 Views11314
    Read More
  5. Windows 에 설치 된 JRE 설치 위치 확인 하기.

    Date2015.05.28 CategoryWindows By성진 Views12571
    Read More
  6. CUBRID와 MyBATIS 빠르게 연동하기

    Date2015.05.07 CategoryJava By김승훈 Views19141
    Read More
  7. CUBRID Linux 부팅시 자동시작 서비스 설정 방법

    Date2013.09.16 CategoryLinux By정만영 Views25479
    Read More
  8. phpize를 이용한 PHP 모듈 연동 방법(CUBRID2008 R4.3 버전)

    Date2013.05.16 CategoryPHP By이용미 Views20858
    Read More
  9. Apache, PHP 설치 방법

    Date2013.05.16 CategoryPHP By이용미 Views41248
    Read More
  10. HA 환경 구성 시 데이터 복제 지연이 발생하는 경우 ECHO(7) port를 확인하자.

    Date2012.11.29 Category기타 By손승일 Views26445
    Read More
  11. VB에서 CUBRID ODBC/OLEDB 사용하는 방법 및 샘플코드.

    Date2012.06.30 CategoryODBC/OLEDB Byseongjoon Views26927
    Read More
  12. CUBRID와 Oracle의 Clob 타입 사용 방법 비교.

    Date2012.06.30 CategoryJava Byseongjoon Views54561
    Read More
  13. CUBRID기반으로 XE 운영하기 – 설치가이드

    Date2012.04.13 CategoryInstall Bycubebridge Views30933
    Read More
  14. select .. for update 처리를 위한 Stored Procudure 등록 및 사용법

    Date2011.12.10 Category기타 By남재우 Views24872
    Read More
  15. LINUX CUBRID 4.0 매니저 설치방법

    Date2011.07.19 CategoryInstall By정만영 Views23654
    Read More
  16. CUBRID Ubuntu Launchpad Installation 방법

    Date2011.07.19 CategoryInstall By정만영 Views29604
    Read More
  17. 자주 발생하는 큐브리드(cubrid) 에러 메시지 정리

    Date2011.07.14 Category기타 Byadmin Views81438
    Read More
  18. [주의사항] CUBRID에서의 BLOB/CLOB 사용시 백업 및 복구에 대한 주의 점

    Date2011.07.14 Category기타 Byadmin Views52792
    Read More
  19. CUBRID 매니저 R3.1에서 웹호스팅 서버의 CUBRID R2.1 접속하는 방법 (큐브리드 매니저에서 다른 버전의 큐브리드 서버 접속 방법)

    Date2011.07.14 Category기타 Byadmin Views31509
    Read More
  20. 동시 접속자에 따른 파라미터 설정

    Date2011.07.14 Category기타 Byadmin Views25686
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 Next
/ 9

Contact Cubrid

대표전화 070-4077-2110 / 기술문의 070-4077-2113 / 영업문의 070-4077-2112 / Email. contact_at_cubrid.com
Contact Sales