我有一个 Web 服务方法来比较模板,但是它不执行在 try catch 块中找到的 if else 语句中的代码,而是返回最后一个显示“错误”的返回语句。知道做错了什么吗?它应该返回“手指已验证”或“手指未验证”。
@WebMethod(operationName = "verify")
public String verify(@WebParam(name = "name") String name, @WebParam(name = "ftset") String ftset) {
Connection con = null;
String dbTemplate = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/biodb", "root", "1234");
PreparedStatement st;
st = con.prepareStatement("select template from info where name = ? ");
st.setString(1, name);
ResultSet result = st.executeQuery();
if (result.next()) { //.next() returns true if there is a next row returned by the query.
dbTemplate = result.getString("template");
byte[] byteArray = new byte[1];
byteArray = hexStringToByteArray(dbTemplate);
DPFPTemplate template = DPFPGlobal.getTemplateFactory().createTemplate();
template.deserialize(byteArray);
byte[] fsArray = new byte[1];
fsArray = hexStringToByteArray(ftset);
DPFPFeatureSet features = null;
features.deserialize(fsArray);
DPFPVerification matcher = DPFPGlobal.getVerificationFactory().createVerification();
DPFPVerificationResult fresult = matcher.verify(features, template);
if (fresult.isVerified()) {
return "The fingerprint was VERIFIED.";
} else {
return "The fingerprint was NOT VERIFIED.";
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
if (con != null) {
try {
con.close();
} catch (SQLException e) {
}
}
}
return "error";
}