【发布时间】: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