简体   繁体   English

无法在带有WSDL的Java中使用SOAP Web服务从数据库检索数据(glassfish服务器)

[英]Can't retrieve data from database using SOAP web service in java with WSDL (glassfish server)

I wanna retrieve data from mysql database using web service written in java with SOAP and WSDL I have written the code and tested it in main function and working well but when I deploy it the results is set to 0 when I use glassfish server as a client and here is the code. 我想使用SOAP和WSDL用Java编写的Web服务从mysql数据库中检索数据,我已经编写了代码并在主函数中对其进行了测试,并且运行良好,但是当我部署它时,当我使用glassfish服务器作为客户端时,结果设置为0这是代码。

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

public class UsersImpl implements Users { 公共类UsersImpl实现Users {

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;
    }

}

} }

and the interface code is 接口代码是

@WebService

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

@WebMethod
int getUserCount();

} }

我认为您应该在try循环中关闭连接,而不要在Final循环中!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从soap web服务中检索未知的XML并使用java插入数据库 - How to retrieve Unknown XML from soap web service and insert into database using java 在wsdl中找不到Soap Web服务模式位置 - Soap web service schema location can't be found in wsdl 使用Maven从WSDL获得的简单(独立)Java SOAP Web服务客户端 - Simple (standalone) Java SOAP web service client from WSDL using Maven 如何使用Eclipse在Core Java中使用WSDL文件(WSDL文件使用SOAP)创建Web服务? - How to create Web Service using WSDL file (WSDL file is using SOAP) in Core Java using Eclipse? 无法使用Java代码访问Web服务,但是通常可以从Chrome看到其wsdl - Web Service can't be accessed in Java code, but its wsdl can be normally seen from Chrome 在CXF中使用wsdl2java生成Web服务服务器实现 - Generating a web service server implementation using wsdl2java in CXF 有没有办法从 WSDL 生成 Java 中的 SOAP 服务器? - Is there a way to generate a SOAP Server in Java from a WSDL? 使用Web Service从数据库检索数据 - Retrieve data from database with Web Service 带有glassfish服务器4.1.1的autodeploy Web服务Java? - autodeploy web service java with glassfish server 4.1.1? Java 8 和 Glassfish 5 中带有自定义类参数的 SOAP Web 服务 - SOAP Web Service with Custom Class Argument in Java 8 and Glassfish 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM