background image
<< CLOB data type | DECIMAL data type >>

DATE data type

<< CLOB data type | DECIMAL data type >>
Derby Reference Manual
196
Use the getClob method on the java.sql.ResultSet to retrieve a CLOB handle to the
underlying data.
Related information
See
Mapping of java.sql.Blob and java.sql.Clob interfaces
.
Example
import java.sql.*;
public class clob
{
public static void main(String[] args) {
try {
String url = "jdbc:derby:clobberyclob;create=true";
// Load the driver. This code is not needed if you are using
// JDK 6, because in that environment the driver is loaded
// automatically when the application requests a connection.
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
Connection conn = DriverManager.getConnection(url);
Statement s = conn.createStatement();
s.executeUpdate(
"CREATE TABLE documents (id INT, text CLOB(64 K))");
conn.commit();
// --- add a file
java.io.File file = new java.io.File("asciifile.txt");
int fileLength = (int) file.length();
// - first, create an input stream
java.io.InputStream fin = new java.io.FileInputStream(file);
PreparedStatement ps = conn.prepareStatement("INSERT
INTO documents VALUES (?, ?)");
ps.setInt(1, 1477);
// - set the value of the input parameter to the input stream
ps.setAsciiStream(2, fin, fileLength);
ps.execute();
conn.commit();
// --- reading the columns
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);
}
}
}
DATE data type
DATE provides for storage of a year-month-day in the range supported by java.sql.Date.