Domanda

i am trying to run another query after pin is confirmed.

The First "TRY" will run query to card db table that only contains card number and pin code. the second "TRY" will run query from another table with other information. i want second "TRY" to run only if the pinn and pindb are matched.

if(e.getSource()==okbutton){
        promptfr.setVisible(false);

        String card=cardnumber.getText();
        String pinn=pincode.getText();
        String pindb=null;
        String pinsql="SELECT *  FROM `card` WHERE `card_number`="+card+";";
        try{
            Class.forName(jdbc_driver);
            con=DriverManager.getConnection(db_url, "root", "");
            ps=con.prepareStatement(pinsql);
            rs=ps.executeQuery();
            if(rs.next());{
                pindb=rs.getString("code")+"";
                System.out.println(pinn+" "+pindb);

            }}
            catch(Exception g){
                System.out.println("Not Found!");
                g.printStackTrace();
            }


        String sql="SELECT *  FROM `user` WHERE `card_number`="+card+";";
        try{

            Class.forName(jdbc_driver);
            con1=DriverManager.getConnection(db_url, "root", "");
            ps1=con1.prepareStatement(sql);
            rs1=ps1.executeQuery();
            if(rs1.next());{
                surname = rs1.getString("ovog")+"";
                name  =rs1.getString("ner")+"";
                id = Integer.parseInt(rs1.getString("id")+"");
                cardnum = Long.parseLong(rs1.getString("card_number")+"");
                balance = Integer.parseInt(rs1.getString("dvn")+"");
                System.out.println("ID:"+id+"\nName:"+name+"\nSurname:"+surname+"\nCard Number:"+cardnum+"\nBalance:"+balance);
                information.setText("ID:"+id+"\nName:"+name+"\nSurname:"+surname+"\nCard Number:"+cardnum+"\nBalance:"+balance);
                }

            }

            catch(Exception g){
                System.out.println("Not Found!");
                g.printStackTrace();
            }}
È stato utile?

Soluzione

if(pindb.equals(pinn)){
//run 2nd query
}

Altri suggerimenti

Simply have an boolean variable . Store the result of first query in the variable .

 if(value==true){
// Run the 2nd query     
}

Hope this helps!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top