Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JAVA about select. please Help me

First I want to make second select function in my java. first is SelectAll which show all data of my DB.
and second is select which show data that fits the conditions.
Second I want to make a Checkbox in data.
and Final when I check the checkbox to true, The data which is checked insert into ArraList

       JCheckBox[] buttons = new JCheckBox[4];  
       JCheckBox ch = new JCheckBox("전체선택",false);      
        j2 = new JButton("초기화");
        panel.add(l1);
        panel.add(tf1);
        panel.add(j1);
        panel.add(ch);
        panel.add(j2);      
        this.add("North",panel); 
        JButton s1 = new JButton("보내기");
        p1.add(s1);
        this.add("South",p1); // 부착     
                connect(); // DB접속하는 메소드    
                selectAll();
            //select();
            j1.addActionListener(e -> {             
                userValue = tf1.getText();  
                select();                       
             }); 
    }    
    public void selectAll() {//this is a 'select' function which is show all data of my DB      
        try { 
            String sql="select name, phone, address from login"; 
            pstmt=con.prepareStatement(sql);
            System.out.println("pstmt : "+pstmt);
            rs1=pstmt.executeQuery(); 
            System.out.println("rs : "+rs);                 
            while(rs1.next()) {
                String name=rs1.getString("name");
                String age=rs1.getString("phone");
                String tel=rs1.getString("address");                                  
              Object data[]= {name,age,tel};
                model.addRow(data);                     
            }
        }catch(Exception e) {
            System.out.println("select() 실행 오류 : " +e);
        }
    } 
public void select()  {//this is a second Search 
         try {           
             pstmt.setString(1, userValue);
            String sql="select name,phone,address from login where name = ?"; 
            pstmt=con.prepareStatement(sql);             
             rs=pstmt.executeQuery(); 
             while(rs.next()) {
                 String name=rs.getString("name");
                 String age=rs.getString("phone");
                 String tel=rs.getString("address");                       
                 Object data[]= {name,age,tel};              
                 model.addRow(data); 
             }
         }  catch(Exception e1) {
             System.out.println("select() 실행 오류 : " +e1);
         } 
    }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is wrong: Assigning parameters to a PreparedStatement before creating it:

PS pstmt.setString(1, userValue);
String sql="select name,phone,address from login where name = ?"; 
pstmt=con.prepareStatement(sql);             

Change to:

String sql="select name,phone,address from login where name = ?"; 
pstmt=con.prepareStatement(sql);             
pstmt.setString(1, userValue);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading