Am writing a SOAP web service method to compare a template with a feature set using digital persona sdk in java. I need to retrieve the template which is a string in database then convert it to a byte array in order to do the matching with the feature set. My input parameters for the web method is email and ftSet which are both string. Ftset also needs to be converted into byte array, these are done after the try catch block. How can i get access to the variable named "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.";
}
}
Declare dbTemplate after declaring the Connection object. In your code, dbTemplate is declared within the try block so anything after the try block does not know what it means.
Connection con = null;
String dbTemplate = null;
Nobody other than this "if" block knows what dbTemplate is.
if (result.next()) { //.next() returns true if there is a next row returned by the query.
String dbTemplate = result.getString("template");
}