???JDBC4.0????Oracle??BLOB?????????
?????excalimax ???????[ 2016/8/25 14:12:09 ] ????????????? Oracle
?????????jar??
???????ojdbc6.jar
??????/META-INF/MANIFEST.MF????????Specification-Version: 4.0
????????
create sequence seq_blobmodel_id start with 1 increment by 1 nocache;
create table blobmodel
(
blobid number(10) primary key not null??
image blob
);
?????????д???????
1 /**
2 * ????????????????
3 * @throws SQLException
4 * @throws IOException
5 */
6 public int writeBlob(String path) throws SQLException?? IOException{
7 int result = 0;
8 String sql = "insert into blobmodel(blobid??image) values(seq_blobmodel_id.nextval???)";
9 //1.????Blob
10 Blob image = DBHelper.getConnection().createBlob();
11 //2.????????blob
12 OutputStream out = image.setBinaryStream(1);
13 //3.?????????д???????
14 FileInputStream fis = new FileInputStream(path);
15 byte []buf = new byte[1024];
16 int len = 0;
17 while((len=fis.read(buf))!=-1){
18 out.write(buf?? 0?? len);
19 }
20 result = DBHelper.executeUpdate2(sql?? new Object[]{image});//??????????jdbc????
21
22 fis.close();
23 out.close();
24 return result;
25 }
?????????????????ж???
/**
* ????????е????????????
* @throws SQLException
* @throws IOException
*/
public void readBlob() throws SQLException?? IOException{
String sql = "select image from blobmodel where blobid=?";
DBHelper.getConnection();//
ResultSet rs = DBHelper.executeQuery(sql?? new Object[]{1});
while(rs.next()){
Blob image = rs.getBlob(1);
InputStream is = image.getBinaryStream();
BufferedInputStream bis = new BufferedInputStream(is);
String path = "img/"+new Date().getTime()+".jpg";//???????????????μ?img?????
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(path));
byte []buf = new byte[1024];
int len = 0;
while((len=bis.read(buf))!=-1){
bos.write(buf??0??len);
}
bos.close();
bis.close();
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11