Why when I update one row in the database, all the options are updated correctly, but the image of another row is edited.
For example, I edit ID number 1, the date is edited correctly, but the photo of row 3 of the database is changed. But there is no change in the photo of row 1
SQL SERVER Table
ID int Unchecked Dates date Checked images image Checked
Java Swing Code
byte[] person_image = null; private void btnbrowsActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: PlatformImpl.startup(() -> { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("tests"); fileChooser.getExtensionFilters().addAll( new FileChooser.ExtensionFilter("JPG Files", "*.jpg") // ,new FileChooser.ExtensionFilter("PNG Files", "*.png") ); File selectedFile = fileChooser.showOpenDialog(null); if (selectedFile != null) { if (selectedFile.exists()) { System.out.println(selectedFile.getPath()); filename = selectedFile.getPath(); TxtPath.setText(filename); ImageIcon imageIcon = new ImageIcon(new ImageIcon(filename).getImage().getScaledInstance(lbl_img.getWidth(), lbl_img.getHeight(), Image.SCALE_SMOOTH)); lbl_img.setIcon(imageIcon); try { File image = new File(filename); FileInputStream fis = new FileInputStream(image); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; for (int readNum; (readNum = fis.read(buf)) != -1;) { bos.write(buf, 0, readNum); } person_image = bos.toByteArray(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e, "warning!", JOptionPane.WARNING_MESSAGE); } } } }); } private void btneditActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); String url = "jdbc:sqlserver://SHA-HumanSrv-01:1433;DatabaseName=Human;user=sa;password=@rsham357987;encrypt=true;trustServerCertificate=true;loginTimeout=30"; Connection con = DriverManager.getConnection(url); String query = "UPDATE Test SET Dates=?,images=? where ID=" + TxtID.getText(); PreparedStatement pst = con.prepareStatement(query); pst.setString(1, datePicker1.getDate()); pst.setBytes(2, person_image); pst.executeUpdate(); JOptionPane.showMessageDialog(null, "Edit Sucessfully!"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }