I'm trying to update my table using Java JDBC. But I don't have any idea how can I call my Primary Key using Prepared Statement. I try to make an USER_ID
object for the column of my database but don't know where to start. How will I determine if I already updated my database?
CODE
String updateEmployee = employeeTf.getText();
String updateDepartment = departmentTf.getText();
if(updateEmployee.isEmpty() && updateDepartment.isEmpty()){
JOptionPane.showMessageDialog(null, "You didn't update it");
}
else if(updateEmployee.isEmpty()){
JOptionPane.showMessageDialog(null, "Please update your name");
}
else if(updateDepartment.isEmpty()){
JOptionPane.showMessageDialog(null, "Please update your department");
}
else{
String updateQuery = "UPDATE SAMPLE SET EMPLOYEENAME = ?, DEPARTMENT = ? WHERE USER_ID = ?";
try(Connection con = DBUtilities.getConnection(DBType.JDBC);
PreparedStatement myPs = con.prepareStatement(updateQuery);){
myPs.setString(1, employeeTf.getText());
myPs.setString(2, departmentTf.getText());
myPs.setInt(3, "WHAT GOES HERE");
//Execute insert SQL Statement
myPs.executeUpdate();
System.out.print("Updated");
} catch (SQLException ex) {
DBUtilities.processException(ex);
}
}