![](/img/trans.png)
[英]Web Service Method- not returning data from the if else statement found in try catch block
[英]Cannot access a parameter from try catch block of a web service method
我正在編寫一個SOAP Web服務方法,以使用Java中的Digital Persona SDK將模板與功能集進行比較。 我需要檢索數據庫中的字符串模板,然后將其轉換為字節數組,以便與功能集進行匹配。 對於Web方法,我的輸入參數是email和ftSet,它們都是字符串。 Ftset還需要轉換為字節數組,這些操作在try catch塊之后完成。 如何獲得對名為“ dbTemplate”的變量的訪問?
@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.";
}
}
在聲明Connection對象之后聲明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");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.