I am currently facing an issue while trying to update a row by its Id using Java, MySQL, and AngularJS. The problem is that I keep receiving a false response and no changes are reflected in the database.
Below is my Java function:
public boolean modifyClient(int idclient, String fullName, String email, int accountNumber, String password) {
try
{
System.out.println("Editing client with full name: " + idclient);
Connection con = Connexion.getConnection();
// Update statement for MySQL
String query = "UPDATE client SET nomcomplet = ?, mail = ?, numerocompte = ?, mdp = ? WHERE idclient = ?";
PreparedStatement ps = con.prepareStatement(query);
ps.setInt(1, idclient);
ps.setString (2, fullName);
ps.setString (3, email);
ps.setInt (4, accountNumber);
ps.setString (5, password);
ps.executeUpdate();
if(ps.executeUpdate() > 0) {
return true;
}
else
{
return false;
}
}
catch (Exception e)
{
System.out.println("Error with modifyClient() -->" + e.getMessage());
return false;
}
}
Next is my controller function:
@POST
@Path("modifyClient/{idclient}/{fullName}/{email}/{accountNumber}/{password}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public boolean modifyClient(@PathParam("idclient") int idclient, @PathParam("fullName") String fullName, @PathParam("email") String email,@PathParam("accountNumber") int accountNumber, @PathParam("password") String password) {
ClientDao dao = new ClientDao();
return dao.modifyClient(idclient,fullName,email,accountNumber,password);
}
Lastly, here is my AngularJS function:
$http.post('rest/client/modifyClient/'+idclient+'/'+$scope.fullName+'/'+$scope.mail+'/'+$scope.accountNumber+'/'+$scope.password').then(function(data){
alert('modified '+data.data);
})
Your assistance on this matter would be greatly appreciated. Thank you.