我正在编写一个 SOAP Web 服务方法来比较模板与使用 Java 中的数字角色 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.";
}
}