CLOB(??????????????????????????????????????????)?????????????????????2,147,483,647?????????????????????????????????????????????CLOB???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
CLOB?????????????????????????????????????????????K???M???G?????????????????????????????????????????????????????????????????????1024???1024*1024???1024*1024*1024?????????????????????
CLOB????????????(??????????????????)?????????????????????????????????{CLOB |CHARACTER LARGE OBJECT} [ ( ?????? [{K |M |G}] ) ]
?????????????????????????????????CLOB????????????2??????(2,147,483,647)???????????????????????????
java.sql.Clob
CLOB
CLOB??????????????????????????????????????????java.sql.ResultSet?????????getClob???????????????????????????????????????
java.sql.Blob???????????????????????????java.sql.Clob???????????????????????????????????????????????????????????????
import java.sql.*;
public class clob
{
public static void main(String[] args) {
try {
String url = "jdbc:derby:clobberyclob;create=true";
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
Connection conn = DriverManager.getConnection(url);
Statement s = conn.createStatement();
s.executeUpdate("CREATE TABLE documents (id INT, text CLOB(64 K))");
conn.commit();
// --- ??????????????????????????????
java.io.File file = new java.io.File("asciifile.txt");
int fileLength = (int) file.length();
// - ????????????????????????????????????????????????
java.io.InputStream fin = new java.io.FileInputStream(file);
PreparedStatement ps = conn.prepareStatement("INSERT
INTO documents VALUES (?, ?)");
ps.setInt(1, 1477);
// - ???????????????????????????????????????????????????????????????
ps.setAsciiStream(2, fin, fileLength);
ps.execute();
conn.commit();
// --- ???????????????
ResultSet rs = s.executeQuery("SELECT text FROM documents
WHERE id = 1477");
while (rs.next()) {
java.sql.Clob aclob = rs.getClob(1);
java.io.InputStream ip = rs.getAsciiStream(1);
int c = ip.read();
while (c > 0) {
System.out.print((char)c);
c = ip.read();
}
System.out.print("\n");
// ...
}
} catch (Exception e) {
System.out.println("Error! "+e);
}
}
}