I have an sqlite database with table salesman with the following attribute:
----------------------
|code|name|isSelected|
----------------------
By default, each entry will have 0under the isSelected attribute. Logic is that User selects a Salesman by name in a JCombobox. Upon selection, the 0 in the selected Salesman under the isSelected attribute should be 1.
So example, given data entry of Salesman:
----------------------
|code|name|isSelected|
----------------------
|0001|John|0 |
----------------------
Then User selects John, so supposedly, the 0 should be updated to 1.
Here's my code in updating:
public void updateSalesman(String selection){
String updateQuery = "UPDATE SALESMAN SET isSelected = '1' WHERE name = 'selection'"; //problem here
Connection connection = null;
PreparedStatement ps = null;
try{
connection = DBConnection.getConnection();
ps = connection.prepareStatement(updateQuery);
ps.executeUpdate();
}catch(Exception e){
e.printStackTrace();
}
}
I have the update query for making 0 to 1, but I dont know how to indicate in the method to only update 1 Salesman, based on the user's selection.
Aucun commentaire:
Enregistrer un commentaire