JDBC10 Blob二进制对象
时间:2021-07-01 10:21:17
帮助过:2人阅读
将图片输入到数据库中
// String sql="insert into t_user2 (username,headImg) values (?,?)";
// ps=conn.prepareStatement(sql);
// ps.setObject(1, 2);
// ps.setBlob(2, new FileInputStream("d:/img.png"));
// ps.execute();
//读取图片到程序中再转出去
String sql="select * from t_user2 where id=?"
;
ps=
conn.prepareStatement(sql);
ps.setObject(1, 3
);
rs=
ps.executeQuery();
while(rs.next()) {
Blob b=rs.getBlob("headImg"
);
is=
b.getBinaryStream();
byte[] temp=
new byte[1024*10
];
int len;
os=
new FileOutputStream("d:/imgcopy"
);
while((len=is.read(temp))!=-1
){
os.write(temp, 0
, len);
}
JDBC10 Blob二进制对象
标签:byte style res out prepare bsp exec name HERE