【发布时间】:2011-05-20 23:25:40
【问题描述】:
此代码获取图片 test.gif 并将图片位值放入 bytea 列中。
public void addImage() throws SQLException, IOException {
Connection con = openConnection();
File file = new File("test.gif");
FileInputStream fis = new FileInputStream(file);
PreparedStatement ps = con.prepareStatement("INSERT INTO image VALUES (?, ?, ?)");
ps.setString(1, file.getName());
ps.setBinaryStream(2, fis, (int)file.length());
ps.setInt(3,1);
ps.executeUpdate();
fis.close();
}
我的下一个目标是以字节为单位显示保存在数据库中的图片。这是怎么做到的?
【问题讨论】:
-
在哪里显示图片?网页、swing 应用等?
-
在摇摆应用中显示图片。该程序实际上是基于Comand Prompt中的comand,所以应该有一个简单的swing程序显示图片。
标签: java image postgresql