//测试用HashMap
HashMap staff=new HashMap();
staff.put("001","true");
staff.put("002","false");
staff.put("003","false");
import oracle.sql.*;//oracle提供的JDBC包
//写入oracle数据库
Connection con=dbConn.getConnection();
con.setAutoCommit(false);
Statement st=con.createStatement();
//关键!!之所以用了这么长时间就是因为没有对BLOB字段初始化!
//插入新的数据时一定要使用EMPTY_BLOB()对BLOB字段初始化!!!
st.executeUpdate("UPDATE TABLE_NAME SET BLOB_VALUE=EMPTY_BLOB() WHERE ID=10");
ResultSet rs = st.executeQuery(
"SELECT BLOB_VALUE " +
"FROM TABLE_NAME " +
"WHERE id = 10 FOR UPDATE"
);
rs.next();
BLOB myBlob =(BLOB) rs.getObject("BLOB_VALUE");
ObjectOutputStream oos=new ObjectOutputStream(myBlob.getBinaryOutputStream());
oos.writeObject(staff);
oos.flush();
st.execute("commit");
……
//从oracle数据库中读出
Connection con=dbConn.getConnection();
Statement st=con.createStatement();
ResultSet rs2 = st.executeQuery(
"SELECT BLOB_VALUE " +
"FROM TABLE_NAME " +
"WHERE id = 10"
);
rs2.next();
BLOB blob =(BLOB) rs.getObject("BLOB_VALUE");
ObjectInputStream ois=new ObjectInputStream(blob.getBinaryStream());
HashMap h1=(HashMap) ois.readObject();
String s1=(String) h1.get("001");
system.out.println(s1);//打印出“true”
ois.close();