Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: sql server update picture in java swing

  1. #1

    Question sql server update picture in java swing

    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);
            }
        }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: sql server update picture in java swing

    If you don't understand my answer, don't ignore it, ask a question.

  3. #3

    Default Re: sql server update picture in java swing

    Quote Originally Posted by Norm View Post
    this method did not solve my problem

Similar Threads

  1. Replies: 0
    Last Post: July 24th, 2019, 03:29 AM
  2. Java JComboBox and Picture Problem
    By Nicken99 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 29th, 2014, 03:56 AM
  3. HELP - placing picture on top of another picture in Java - JLayerPane
    By smasm in forum What's Wrong With My Code?
    Replies: 39
    Last Post: April 27th, 2012, 07:16 PM
  4. Java Picture Processor with PGM files and Multi Arrays
    By snow_mac in forum Object Oriented Programming
    Replies: 2
    Last Post: November 28th, 2011, 09:55 PM
  5. Converting a picture made up of 0s and 1s into a colored picture??
    By Kranti1992 in forum Java Theory & Questions
    Replies: 10
    Last Post: November 21st, 2011, 06:25 PM

Tags for this Thread