I'm new. Tell me how you can make a data output from the database of one field in the general list of my program.
There are two window controllers:
- Login window. Where the user specifies the login and password is connected. The authorization window closes and the general program window opens.
- General program window with a list of files from the database.
Now I get a general list of data from the database using the query:
public ObservableList<Person> search() { gettingUsersList("SELECT * FROM users ORDER BY id"); return PersonList; } and display it completely in the program. And I would like to display data only for the user who passed authorization.
Wrote this method:
public ObservableList<Person> searchUser(String user) { String searching = "%" + user + "%"; gettingUsersList("SELECT * FROM users WHERE userName = '" + searching + "'"); return PersonList; } Method gettingUsersList
private void gettingUsersList(String sql){ try (Connection con = MysqlConnection.getConnection(); Statement stm = Objects.requireNonNull(con).createStatement(); ResultSet rs = stm.executeQuery(sql)){ while (rs.next()){ Person person = new Person (); person.setId(rs.getInt("id")); person.setUserName(rs.getString("userName")); person.setPassword(rs.getString("password")); person.setFileName(rs.getString("fileName")); person.setSize(rs.getDouble("size")); DropBoxList.add(person); } } catch (SQLException e){ e.printStackTrace(); } } My problem is that I can not figure out how to transfer the user name for output from the database. Now I am trying to take the username from the login field of the authorization form, but I get null;
Tell me what options can be to solve my problem? Thank.