[英]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.