티스토리 뷰

반응형
import java.sql.*;
import java.io.*;

public class OracleClobExample {

    public static void main(String[] args) {

        String url = "jdbc:oracle:thin:@<hostname>:<port>:<sid>";
        String username = "<username>";
        String password = "<password>";

        try (Connection conn = DriverManager.getConnection(url, username, password)) {

            String sql = "INSERT INTO table_name (id, clob_column) VALUES (?,?)";

            try (PreparedStatement pstmt = conn.prepareStatement(sql)) {

                pstmt.setInt(1, 1);

                String clobValue = "This is a test of a CLOB value";
                Reader reader = new StringReader(clobValue);

                pstmt.setCharacterStream(2, reader, clobValue.length());

                int rowsInserted = pstmt.executeUpdate();

                System.out.println("Number of rows inserted: " + rowsInserted);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

 

ChatGPT를 사용하면 필요한 코드를 빠르게 찾을 수 있을 듯 합니다.

 

반응형