Thanks for the sample code. I needed some ready made java app to test some DevOps/Ansible automation stuff i was working on and this app came in handy. However there were a couple things I would like to add here.
These two files are same and are Redundant code. both use the same annotation "/register" and causes the app to throw errors. (any) One of it needs to be removed.
2.) Though this is a sample application, it would have been good if it allowed to register more than one user. As of now, only one user can be registered and any further attempts to add new users will cause error. This is because the dao class is fixing the ID to 1 every time its invoked.
For those who want to change this behaviour, should update the following code.
Removing ID from the SQL String and in Prepared statements, and adjusting the number of ?/Parameters in both places.
String INSERT_USERS_SQL = "INSERT INTO employee" +
" (first_name, last_name, username, password, address, contact) VALUES " +
" (?, ?, ?, ?,?,?);";
// Step 2:Create a statement using connection object
PreparedStatement preparedStatement = connection.prepareStatement(INSERT_USERS_SQL)) {
preparedStatement.setString(1, employee.getFirstName());
preparedStatement.setString(2, employee.getLastName());
preparedStatement.setString(3, employee.getUsername());
preparedStatement.setString(4, employee.getPassword());
preparedStatement.setString(5, employee.getAddress());
preparedStatement.setString(6, employee.getContact());