postgresql数据库存储图片文件
来源:互联网 发布:文华模拟交易软件 编辑:程序博客网 时间:2024/06/06 04:01
postgresql数据库使用bytea类型字段
具体存储时使用的是postgresql自定义函数(存储过程)
函数如下:
create or replace function savepicture(xpicture varchar,xpicname varchar)
returns int as $$
begin
insert in temp_picture(picture,picturename) values(cast(xpicture as bytea),xpicname);
return 1;
end $$ language plpgsql;
部分代码处理
String picture= null;
byte[] data = null;
File file = new File(path);
FileInputStream input = null;
try {
input = new FileInputStream (file);
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buf = new byte[(int)file.length()];
int byteread = 0;
try {
while((byteread = input.read(buf))!=-1){
output.write(buf, 0, byteread);
}
data = output.toByteArray();
picture= binarys(data);
output.close();
input.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e1) {
e1.printStackTrace();
}
public static String binarys(byte[] bytes){
StringBuffer sbf = new StringBuffer("");
for (int i = 0; i < bytes.length; i++) {
String tmp = Integer.toOctalString(bytes[i] & 0xff);
switch (tmp.length()) {
case 1:
tmp = "\\00" +tmp;
break;
case 2:
tmp = "\\0" +tmp;
break;
case 3:
tmp = "\\" +tmp;
break;
default:
break;
}
sbf.append(tmp);
}
return sbf.toString();
}
postgresql存储二进制数据需要转为3位八进制数据存储。
- postgresql数据库存储图片文件
- java实现图片文件存储到数据库
- 图片、文件、二进制文件 三种资源不要放进数据库存储
- 关于图片或者文件在数据库的存储方式归纳
- 关于图片或者文件在数据库的存储方式归纳
- 在数据库中存储图片文件,如何实现?
- 关于图片或者文件在数据库的存储方式归纳
- 图片或者其他文件在数据库的存储方式详解
- 关于图片或者文件在数据库的存储方式归纳
- 关于图片或者文件在数据库的存储方式归纳
- 关于图片或者文件在数据库的存储方式归纳
- 关于图片或者文件在数据库的存储方式归纳
- 关于图片或者文件在数据库的存储方式归纳
- 关于图片或者文件在数据库的存储方式归纳
- 关于图片或者文件在数据库的存储方式归纳
- 关于图片或者文件在数据库的存储方式归纳
- 关于图片或者文件在数据库的存储方式归纳
- 关于图片或者文件在数据库的存储方式归纳
- 居中大全
- VC2010用IE调试OCX单步
- Java class对象的详解
- poj-3061-Subsequence 尺取法/双指针法
- 【DP】POJ 2385
- postgresql数据库存储图片文件
- you need to use a Theme.AppCompat theme(or descenbant) with this activity
- java多线程-专题-聊聊并发(十)生产者消费者模式
- 关于st的插件,我之前windows用的插件有哪些?
- UITableView修改Cell的宽度问题
- Android使用http协议的GET和POST方法!!!
- struts2配置文件Demo_Me
- javascript中的数组的使用
- iOS开发-a few animation Effect