Hi
i m trying to get selected from jradiobutton..i m using eclipse and windowbuilder for java
please check my code

JRadioButton btn1 = new JRadioButton("By Trading Name",true);
        btn1.setBounds(22, 48, 149, 23);
        contentPane.add(btn1);

        JRadioButton btn2 = new JRadioButton("By Overshop",false);
        btn2.setBounds(22, 75, 149, 23);
        contentPane.add(btn2);

        JRadioButton btn3 = new JRadioButton("By Address",false);
        btn3.setBounds(22, 102, 149, 23);
        contentPane.add(btn3);

        JRadioButton btn4 = new JRadioButton("By Contact",false);
        btn4.setBounds(22, 129, 149, 23);
        contentPane.add(btn4);
        ButtonGroup bg = new ButtonGroup();

        bg.add(btn1);
        bg.add(btn2);
        bg.add(btn3);
        bg.add(btn4);

    }
    ////next record//////
    private void btnSuivantActionPerformed(ActionEvent evt) {
           count++;

          try{



                    Class.forName("com.mysql.jdbc.Driver");
                    conn = DriverManager.getConnection("jdbc:mysql://localhost/cabinet","root","root");
                    Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);



                    if(btn1).isSelected()){

                        String selectStuff =("Select * From customer WHERE tradingname = '"+search.getText()+"'");
                        ResultSet rows = st.executeQuery(selectStuff);

                    }
                    else if(btn2.isSelected()){
                         String selectStuff =("Select * From customer WHERE overshop = '"+search.getText()+"'  ");
                            ResultSet rows = st.executeQuery(selectStuff);
                    }
                    else if(btn3.isSelected()){
                         String selectStuff =("Select * From customer WHERE address = '"+search.getText()+"'  ");
                         ResultSet rows = st.executeQuery(selectStuff);
                    }
                    else if(btn4.isSelected()){
                         String selectStuff =("Select * From customer WHERE contact1 = '"+search.getText()+"' OR contact2 = '"+search.getText()+"'  ");
                            ResultSet rows = st.executeQuery(selectStuff);
                    }

What exactly is your question?

ps: You do not want to open a new database connection every time the user presses "next/suivant". Just do it once, as part of the initialisation.

thx
my question is when i tick one from radiobutton it is not tested in my query..
i choose Tradingname from radio button then my sql must be where tardingname = search.getText()
or i can choose overshop then the sql will be where overshop =search.getText() and so..

Did you add the action listener to your radio buttons? I can't see the code for that in what you posted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.