0
我有一個Java Swing應用程序和SQLite數據庫的小問題。每當我嘗試使用更新按鈕更新表格中的選定行時,我的應用程序就會將所選行中存儲的圖像從數據庫中刪除。Java swing&sqlite - 更新圖片
我刪除功能:
String sql = "UPDATE PLAYER SET NAME =? , LAST=?, DOB=?, IMAGE=?, GENDER=?, LAST_UPDATE=? WHERE ID_PLAYER=? ";
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
int id = Integer.parseInt(tf_id.getText());
try {
pst = conn.prepareStatement(sql);
pst.setString(1, tf_name.getText());
pst.setString(2, tf_last.getText());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
String d = sdf.format(t_date.getDate());
pst.setString(3, d);
pst.setBytes(4, person_image);
if (combobox_male.isSelected()) {
gender = "MAN";
} else if (combobox_female.isSelected()) {
gender = "WOMAN";
}
pst.setString(5, gender);
pst.setTimestamp(6, timestamp);
pst.setInt(7, id);
pst.executeUpdate();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
我附加圖片功能:
JFileChooser jfc = new JFileChooser();
jfc.showOpenDialog(null);
File f = jfc.getSelectedFile();
filename = f.getAbsolutePath();
tetxfield_attach_image.setText(filename);
lable_picture.setIcon(ResizeImage(filename, null));
try {
File image = new File(filename);
FileImageInputStream fis = new FileImageInputStream(image);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buff = new byte[1024];
for (int readNum; (readNum = fis.read(buff)) != -1;) {
bos.write(buff, 0, readNum);
}
person_image = bos.toByteArray();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
我在哪裏錯了?
對不起,但不可能理解這一點:「我的應用程序,存儲的數據庫中的選定行的數據庫刪除圖像。」 – Berger
你的問題是什麼?更新查詢刪除行? – AxelH
對實際問題的重要澄清將會很有用。 –