爲了執行任務,我必須將圖像作爲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