Blob:
写入:
FileInputStream fis = new FileInputStream(file);
pstmt.setBinaryStream(1, fis, (int) file.length());
... pstmt.close();
fis.close();
读取:
Blob blob = rs.getBlob("photo");
ImageIcon icon = new ImageIcon(blob.getBytes(1, (int)blob.length()));
JLabel lPhoto = new JLabel(icon);
setLayout(new GridLayout(1, 1));
add(lPhoto);
Clob:
写入:
FileInputStream fis = new FileInputStream(file);
pstmt.setAsciiStream(1, fis, (int)file.length());
读取:
Clob clob = rs.getClob("memo");
InputStreamReader in = new InputStreamReader(clob.getAsciiStream());
JTextArea text = new JTextArea(readString(in));
setLayout(new GridLayout(1, 1));
add(text);
public static String readString(InputStreamReader in) throws IOException {
StringBuffer buf = new StringBuffer();
int n;
char[] b = new char[1024];
while((n = in.read(b)) > 0)
buf.append(b, 0, n);
return buf.toString();
}
写入:
FileInputStream fis = new FileInputStream(file);
pstmt.setBinaryStream(1, fis, (int) file.length());
... pstmt.close();
fis.close();
读取:
Blob blob = rs.getBlob("photo");
ImageIcon icon = new ImageIcon(blob.getBytes(1, (int)blob.length()));
JLabel lPhoto = new JLabel(icon);
setLayout(new GridLayout(1, 1));
add(lPhoto);
Clob:
写入:
FileInputStream fis = new FileInputStream(file);
pstmt.setAsciiStream(1, fis, (int)file.length());
读取:
Clob clob = rs.getClob("memo");
InputStreamReader in = new InputStreamReader(clob.getAsciiStream());
JTextArea text = new JTextArea(readString(in));
setLayout(new GridLayout(1, 1));
add(text);
public static String readString(InputStreamReader in) throws IOException {
StringBuffer buf = new StringBuffer();
int n;
char[] b = new char[1024];
while((n = in.read(b)) > 0)
buf.append(b, 0, n);
return buf.toString();
}