728x90
반응형
Tibero Jdbc 를 이용해 Clob 을 조회 하는 샘플소스를 예제를 기록 합니다.
Clob 컬럼을 포함한 샘플 테이블 생성
try {
tbstmt.executeQuery("drop table TEST_CLOB_TBL");
} catch (SQLException e) {
e.printStackTrace();
}
try {
tbstmt.executeQuery("create table TEST_CLOB_TBL (c1 varchar2(10000))");
} catch (SQLException e) {
e.printStackTrace();
}
try {
tbstmt.executeQuery("insert into TEST_CLOB_TBL select level from dual connect by level <= 10");
} catch (SQLException e) {
e.printStackTrace();
}
Clob 컬럼 조회
try {
ResultSet rs = tbstmt.executeQuery("select xmlagg(xmlelement(c1, c1)) as col_clob from TEST_CLOB_TBL");
if (rs.next()) {
TbClob clob = (TbClob) rs.getClob("col_clob");
Reader instream = clob.getCharacterStream();
char[] buffer = new char[10];
int length = 0;
while ((length = instream.read(buffer)) != -1) {
for (int i = 0; i < length; i++)
System.out.print(buffer[i]);
}
instream.close();
}
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
ClobTest.java
import java.io.Reader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.tmax.tibero.jdbc.TbClob;
public class ClobTest {
static String IP = "localhost";
static String PORT = "40060";
static String TB_SID = "tibero";
static String userid = "tibero";
static String pwd = "tmax";
public static void main(String args[]) {
try {
Class.forName("com.tmax.tibero.jdbc.TbDriver");
Connection tbconn;
Statement tbstmt;
tbconn = DriverManager.getConnection("jdbc:tibero:thin:@" + IP + ":" + PORT + ":" + TB_SID, userid, pwd);
tbstmt = tbconn.createStatement();
try {
tbstmt.executeQuery("drop table TEST_CLOB_TBL");
} catch (SQLException e) {
e.printStackTrace();
}
try {
tbstmt.executeQuery("create table TEST_CLOB_TBL (c1 varchar2(10000))");
} catch (SQLException e) {
e.printStackTrace();
}
try {
tbstmt.executeQuery("insert into TEST_CLOB_TBL select level from dual connect by level <= 10");
} catch (SQLException e) {
e.printStackTrace();
}
try {
ResultSet rs = tbstmt.executeQuery("select xmlagg(xmlelement(c1, c1)) as col_clob from TEST_CLOB_TBL");
if (rs.next()) {
TbClob clob = (TbClob) rs.getClob("col_clob");
Reader instream = clob.getCharacterStream();
char[] buffer = new char[10];
int length = 0;
while ((length = instream.read(buffer)) != -1) {
for (int i = 0; i < length; i++)
System.out.print(buffer[i]);
}
instream.close();
}
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
tbstmt.close();
tbconn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
728x90
반응형
'05.DB > Tibero' 카테고리의 다른 글
Tibero TAC 설치 (0) | 2023.03.13 |
---|---|
Tibero RODBC 연동 방법 (1) | 2023.03.02 |
[TDP.net] Tibero TDP.net 테스트 방법 (0) | 2022.04.28 |
[Tibero-Django] Django Tibero 연동 방법 (0) | 2022.04.15 |
[Tibero]Tibero ODBC 연동 (0) | 2022.04.11 |