保存
---
Vector v=new Vector();
v.add("hogehoge");
v.add("aheahe");
File outf=new File("tmp.dat");
ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream(outf));
out.writeObject(v);
out.flush();
out.close();
File inf=new File("tmp.dat");
FileInputStream fis=new FileInputStream(inf);
String statement="insert into test(key,object) values ('person',?)";
PreparedStatement ps = _con.prepareStatement(statement);
ps.setBinaryStream(1, fis,(int)inf.length());
ps.executeUpdate();
ps.close();
fis.close();
--
读取
--
String statement ="select object from test where key='person'";
PreparedStatement ps = _con.prepareStatement(statement);
ResultSet rs = ps.executeQuery();
if (rs != null) {
while (rs.next()) {
InputStream is=rs.getBinaryStream("object");
ObjectInputStream ois=new ObjectInputStream(is);
Vector v=(Vector)ois.readObject();
System.out.println("vector:"+v);
}
rs.close();
}
ps.close();