PIN码验证命令?

时间:2014-04-28 10:42:45

标签: java database validation if-statement try-catch

我确定在确认引脚后尝试运行另一个查询。

第一个"尝试"将运行查询到只包含卡号和密码的卡片db表。第二个"尝试"将使用其他信息从另一个表运行查询。我想要第二个"尝试"仅在pinn和pindb匹配时运行。

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

2 个答案:

答案 0 :(得分:0)

只需拥有一个boolean变量。将第一个查询的结果存储在变量中。

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

希望这有帮助!

答案 1 :(得分:0)

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