【问题标题】:Can't retrieve data from database using SOAP web service in java with WSDL (glassfish server)无法使用带有 WSDL(glassfish 服务器)的 Java 中的 SOAP Web 服务从数据库中检索数据
【发布时间】:2016-06-05 19:03:47
【问题描述】:

我想使用带有 SOAP 和 WSDL 的 java 编写的 Web 服务从 mysql 数据库中检索数据我已经编写了代码并在主函数中对其进行了测试并且运行良好,但是当我部署它时,当我使用 glassfish 服务器时结果设置为 0作为客户,这里是代码。

@WebService(endpointInterface = "javasamples.two.Users")

公共类UsersImpl实现用户{

public int getUserCount() { 
    int numusers = 0;
    String dbUrl = "jdbc:mysql://localhost:3306/javasql";
    String dbClass = "com.mysql.jdbc.Driver";
    String query = "Select count(*) FROM user";
    String userName = "root", password = "admin";
    try {

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection (dbUrl, userName, password);
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(query);

    while (rs.next()) {
        numusers = rs.getInt(1);
        } //end while
        con.close();
    } //end try

    catch(ClassNotFoundException e) {
        e.printStackTrace();
    }

    catch(SQLException e) {
        e.printStackTrace();
    }
    finally {

        return numusers;
    }

}

}

接口代码是

@WebService

@SOAPBinding(style = Style.RPC) 公共接口用户{

@WebMethod
int getUserCount();

}

【问题讨论】:

    标签: java soap web service wsdl


    【解决方案1】:

    我认为你应该在 try 循环中关闭连接,而不是在最后一个!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      相关资源
      最近更新 更多