Is it possible to add a new record (new user) to the table that was extracted from the database? When you click the button, the fields for data entry and the button for saving them must open! I use jsf, the data is displayed in the xhtml page. Tell me please! Is everything clear, I explain!?
Methods for adding and saving new data: (myList- new ArrayList; Values - class containing setters & getters. With the new list, everything is opened and added, but how to combine myList with getAllUsers () if I explain correctly?
public void addNewUser(){ Values newValue = new Values(); newValue.setEditable(true); myList.add(newValue); } public void saveNewUser(){ System.out.println("We're in saveNewUser()"); for(Values value: myList){ addUser(); value.setEditable(false); } } Method that retrieves data from the database:
public ArrayList<Values> getAllUsers(){ ArrayList<Values> usersList= new ArrayList<>(); SQL= "SELECT id,orderNo,productName,price,qty FROM Registration"; System.out.println("Retreive values from Registration table..."); databaseConnection(); try { prepStatement= connection.prepareStatement(SQL); resultSet= prepStatement.executeQuery(); boolean found= false; while (resultSet.next()== true) { Values allValues= new Values(); allValues.setId(resultSet.getInt("id")); allValues.setOrderNo(resultSet.getString("orderNo")); allValues.setProductName(resultSet.getString("productName")); allValues.setPrice(resultSet.getBigDecimal("price")); allValues.setQty(resultSet.getInt("qty")); usersList.add(allValues); found= true; } resultSet.close(); prepStatement.close(); if (found) { return usersList; } else { return null; } } catch (Exception e) { // TODO: handle exception e.printStackTrace(); System.out.println("Error in getAllUsers()-->"+e.getMessage()); }finally { close(connection); } return (null); } public List<Values> getInformation(){ return getAllUsers(); } 