postgresql存图片字段类型_postgresql数据库存储图片文件

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=


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部