我有一個圖像名爲P100.jpg
。我正在調整它,它被轉換成ZP100.png
。我通過插入查詢將它存儲到數據庫MySQL中。從數據庫檢索圖像並在標籤中顯示
File imageFile = new File("F:\\POSTERS\\Roses\\ZP100.png");
FileInputStream fis = new FileInputStream(imageFile);
String insertImage = "insert into image values(?,?)";
prestmt = con.prepareStatement(insertImage);
prestmt.setInt(1,4);
prestmt.setBinaryStream(2, fis, fis.available());
result = prestmt.executeUpdate();
現在我想檢索該圖像並通過將其分配給標籤來顯示在窗體上。
String selectImage = "select img from image";
prestmt = con.prepareStatement(selectImage);
但它給我的異常,因爲
java.sql.SQLException: Can not issue executeUpdate() for SELECTs
對於一個標籤賦予圖像,我有:
image.setText("ZP100.png");
我知道,這是行不通的。請幫我重新編碼這個。
任何人都可以請幫我...... – Anjali
檢查我的答案 –