I have a soap web service that is connected to mySQL database. It has two methods, one is insert() and the other is verify(). The first one enables the user to enter data such as name, email and password. It saves the records in the database successfully.
However am having problems with writing the verify method. It has as input parameters, email and password. It must compare the data entered with those stored in the database and return “registered” or “not registered” if it cant find the match in mysql database. Am having problem writing the codes. Could you please help, am new to jdbc and java web services. Am using netbeans.
Thanks a lot.
Here are my codes:
@WebMethod(operationName = "insert")
public String insert(@WebParam(name = "name") String name,
@WebParam(name = "email") String email,
@WebParam(name = "password") String password {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root", "1234");
PreparedStatement st = con.prepareStatement("insert into register values(?,?,?)");
st.setString(1, name);
st.setString(2, email);
st.setString(3, password);
st.executeUpdate();
} catch (Exception e) {
System.out.println(e.getMessage());
}
return "record inserted";
}
/**
* Web service operation
*/
@WebMethod(operationName = "Verify")
public String CheckUser(@WebParam(name = "email") String email,
@WebParam(name = "password") String password) {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root", "1234");
If
// problems to write this statement!!! I need to compare the username and password
// with some select * from register where password == @password and email == @email?
return "Registered user";
else
return "Not registered";
}
This example could work (you might have to change column names in the query). Also, you should close the connection in the insert method, in the same way that this example.