0

我正在编写一个 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.";

            }  

}
4

1 回答 1

1

在声明 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");
}
于 2012-11-08T04:45:02.810 回答