2012-11-08 114 views
0

正在編寫SOAP Web服務方法,以使用java中的數字角色sdk將模板與功能集進行比較。我需要檢索數據庫中的字符串模板,然後將其轉換爲字節數組,以便與特徵集進行匹配。我的web方法的輸入參數是email和ftSet,它們都是字符串。 Ftset也需要轉換成字節數組,這些都是在try catch塊之後完成的。我怎樣才能訪問名爲「dbTemplate」的變量?無法從Web服務方法的try catch塊訪問參數

@WebMethod(operationName = "CheckTemplate") 
public String CheckTemplate(@WebParam(name = "email") String email, 
     @WebParam(name = "ftSet") String ftSet) { 

    Connection con = null; 
    try { 
     Class.forName("com.mysql.jdbc.Driver"); 
     con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root", "1234"); 
     PreparedStatement st; 
     st = con.prepareStatement("select template from Tbl_reg where email = ? "); 
     st.setString(1, email); 

     ResultSet result = st.executeQuery(); 

     if (result.next()) { //.next() returns true if there is a next row returned by the query. 

      String dbTemplate = result.getString("template"); 


     } 
    } catch (Exception e) { 
     System.out.println(e.getMessage()); 

    } finally { 
     if (con != null) { 
      try { 
       con.close(); 

      } catch (SQLException e) { 
      } 
     } 
    } 


      byte[] byteArray = new byte[1]; 
//dbTemplate is underlined here, cannot access it from the try catch 
      byteArray = hexStringToByteArray(dbTemplate); 
      DPFPTemplate template = DPFPGlobal.getTemplateFactory().createTemplate(); 
      template.deserialize(byteArray); 


      byte[] fsArray = new byte[1]; 
      fsArray = hexStringToByteArray(ftSet); 
      DPFPSample sample = DPFPGlobal.getSampleFactory().createSample(); 
      sample.deserialize(fsArray); 

      DPFPFeatureSet features = extractFeatures(sample, DPFPDataPurpose.DATA_PURPOSE_VERIFICATION); 


      DPFPVerification matcher = DPFPGlobal.getVerificationFactory().createVerification(); 
      DPFPVerificationResult result1 = matcher.verify(features, template); 

      if (result1.isVerified()) { 

       return "The fingerprint was VERIFIED."; 

      } else { 
       return "The fingerprint was NOT VERIFIED."; 

      } 

} 

回答

1

聲明連接對象後聲明dbTemplate。在你的代碼中,dbTemplate是在try塊內聲明的,所以在try塊之後的任何東西都不知道它的意思。

Connection con = null; 
String dbTemplate = null; 

除了這個「if」塊之外,沒有人知道dbTemplate是什麼。

if (result.next()) { //.next() returns true if there is a next row returned by the query. 
    String dbTemplate = result.getString("template"); 
} 
+0

好的非常感謝你。 但我現在正在得到另一個錯誤。它沒有返回任何東西。 ? 給我的錯誤:( – Div

+0

什麼是不返回任何東西有什麼錯誤 –

+0

,而不是返回指紋,驗證或沒有驗證正在此錯誤: 服務調用拋出異常與消息:無效;請參考服務器日誌更多詳細信息 異常詳細信息:java.lang.reflect.InvocationTargetException – Div