无法从Web服务方法的try catch块访问参数

时间:2012-11-08 04:40:47

标签: java web-services netbeans-7 fingerprint

编写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.";

            }  

}

1 个答案:

答案 0 :(得分: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");
}