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
对实际问题的重要澄清将会很有用。 –