为了执行任务,我必须将图像作为Blob格式存储到MySQL中(尽管存储图像路径会更好,更理想在数据库中并将图像保存在localcopy中的文件夹中)。如何着手将图像以Blob格式保存到Java中的Java
到目前为止,我已经研究,但没有找到任何答案,可以帮助我,这是我迄今所做
不久,单击按钮,这将被解雇:
empdao.insertImage(fis);
图像填充另一个甚至听者这样的:
static FileInputStream fis = null;
static String path = null;
path = filechooser.getSelectedFile().getAbsolutePath();
File image = new File(path);
fis = new FileInputStream (image);
这下面的代码需要将它添加到数据库中的护理。
public void insertImage(FileInputStream fis) throws SQLException {
Connection c = getConnection();
String query = "INSERT INTO Picture (picture) VALUES (?)";
System.out.println(query);
PreparedStatement pstmt = c.prepareStatement(query);
pstmt.setBinaryStream(1, fis);
pstmt.executeUpdate();
c.close();
}
但问题是,我需要它,将其转换为一个blob,我不知道如何,有人可以帮助我或者指导我如何去选择的图像存储为一个BLOB字段成MySQL的。
当前它将它添加到数据库中时,我在图片列中获得了java.io文件输入。
http://stackoverflow.com/a/41235395/267540 – e4c5