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.
@WebService(endpointInterface = "javasamples.two.Users")
public class UsersImpl implements 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 {
@WebMethod
int getUserCount();
}
Aucun commentaire:
Enregistrer un commentaire