2014-04-28 37 views
0

我試圖在引腳確認後運行另一個查詢。引腳代碼驗證命令?

第一個「TRY」將對包含卡號和PIN碼的卡數據庫表執行查詢。第二個「TRY」將從另一個表中運行查詢和其他信息。我希望第二個「TRY」只有在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(); 
      }} 

回答

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

只要有一個boolean變量。將第一個查詢的結果存儲在變量中。

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

希望這會有所幫助!

+0

試過不工作,不運行任何東西,如果之後(價值==真){// 運行第二個查詢 } – Biligsaikhan

+0

任何'例外?',也清楚地說明你嘗試過什麼? –