DB Tips

¹«´À¹Ì
2004-04-09 18:31:08.0
¿À¶óŬ 10g¿¡¼­´Â LOBS¸¦ »ç¿ëÇÏ´Â ¹æ¹ý¿¡ º¯°æÀÌ ÀÖ±º¿ä.

¿À¶óŬ 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();
...........

 

¿À¶óŬ¿¡¼­ ÆÛ¿Ô½¿´ç.

Tag
tag´Â °Ô½Ã¹°ÀÇ ¼º°ÝÀ» ³ªÅ¸³»´Â Ű¿öµå¸¦ ÀÔ·ÂÇÏ´Â °ø°£ÀÔ´Ï´Ù.
tag´Â ·Î±×ÀÎ ÈÄ »ç¿ëÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.
  • ¿ÀÈ£~ Àß ºÃ½À´Ï´Ù.
  • »ïµð
  • 2004-07-31 14:55:06
  • x
  • ¾Æ...
  • ¹é°õ
  • 2004-09-08 17:17:02
  • x
´ÙÀ½±Û [Âü°í] No Sql°ú ¿©ÀüÈ÷ »ì¾ÆÀÖ´Â SQL
>> 244 ¿À¶óŬ 10g¿¡¼­´Â LOBS¸¦ »ç¿ëÇÏ´Â ¹æ¹ý¿¡ º¯°æÀÌ ÀÖ±º¿ä.  [2] ¹«´À¹Ì 4014 04-09 18:31
ÀÌÀü±Û Angel 1.6 v SQL Tool (Plan Tool Upgrade)