¿À¶óŬ 10g¿¡¼´Â standard API·Î clob¸¦ »ç¿ëÇÒ ¼ö ÀÖµµ·Ï ¼öÁ¤µÇ¾ú´Ù°í ÇÕ´Ï´Ù.
http://otn.oracle.com/sample_code/tech/java/codesnippet/jdbc/clob10g/handlingclobsinoraclejdbc10g.html?_template=/otn/content/print
Âü°í´Â À§ÀÇ ¿À¶óŬ¿¡¼ °¡´ÉÇÕ´Ï´Ù.
°£´ÜÇÏ°Ô º¸ÀÚ¸é
ù¹øÂ° setString()ÇÔ¼ö·Î ±âÁ¸ÀÇ ´Ù¸¥ int³ª String ŸÀÔÀ» preparedStatmemt¿¡ Ãß°¡ÇϵíÀÌ °°Àº ¹æ¹ýÀ¸·Î Ãß°¡ Ç쵂 connectionString¿¡ setBigStringTryClob=true¸¦ Ãß°¡ÇØ Áà¾ß ÇÑ´Ù°í ÇÕ´Ï´Ù.
µÎ¹øÂ° ¹æ¹ýÀº Ç¥ÁØ preparedStatment¸¦ ´ë½ÅÇÏ¿© OraclePreparedstatment¸¦ »ç¿ëÇÏ¿©, ¿À¶óŬÇÁ¸®Æä¾î½ºÅ×ÀÌÆ®¸ÕÆ®ÀÇ setStringForClob()¸¦ »ç¿ëÇÏ¿© ó¸®ÇÏ´Â ¹æ¹ýÀÌ ¼Ò°³µÇ¾î ÀÖ½À´Ï´Ù.
±âº»È¯°æ
import java.sql.Connection;
import java.sql.DriverManager;
import oracle.jdbc.OracleDriver;
import java.util.Properties;
..........
// Load the database details into the variables.
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
String user = "scott";
String password = "tiger";
// Create the properties object that holds all database details
Properties props = new Properties();
props.put("user", user );
props.put("password", password);
props.put("SetBigStringTryClob", "true");
// Load the Oracle JDBC driver class.
DriverManager.registerDriver(new OracleDriver());
// Get the database connection
Connection conn = DriverManager.getConnection( this.url, this.props );
ù¹øÀç ¹æ¹ý
PreparedStatement pstmt = conn.prepareStatement(
"INSERT INTO clob_tab VALUES(?)");
// Read a big file(larger than 32765 bytes).
// Note: method readFile() not listed here.
// It can be any method that reads a file.
String str = this.readFile("bigFile.txt");
// The string data is automatically transformed into a CLOB and
// inserted into the database column.
// Make sure that the Connection property - 'SetBigStringTryClob' is
// set to true for the insert to happen.
pstmt.setString(1, str);
pstmt.executeUpdate();
µÎ¹øÀç ¹æ¹ý
import java.sql.*;
import java.io.*;
import java.util.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.*;
..........
// Create SQL query to insert CLOB data and other columns in the database.
String sql = "INSERT INTO clob_tab VALUES(?)";
// Read a big file(larger than 32765 bytes).
// Note: method readFile() not listed here.
// It can be any method that reads a file.
String str = this.readFile("bigFile.txt");
// Create the OraclePreparedStatement object
opstmt = (OraclePreparedStatement)conn.prepareStatement(sql);
// Use the new method to insert the CLOB data (for data greater or lesser than 32 KB)
opstmt.setStringForClob(1,str);
// Execute the OraclePreparedStatement
opstmt.executeUpdate();
...........
¿À¶óŬ¿¡¼ ÆÛ¿Ô½¿´ç.