I make an application on JavaFX. SQLite database.

There is a table "category1" and fields in it: "ID", "question, answer"

table

In the main window, I have two labels. When I start the application, I fill the database. My application has the function of adding texts, deleting, or editing. The number of rows in the base SQlite will constantly change.

I need to save the text from each column to an array (any list from the collection framework) The text from the question column is associated with the text from the "answer" column for each row in the table.

If I press, for example, the number 1 on the keyboard, then one random question from the array should appear in the first label, and the corresponding answer should appear in another label. After the texts appear, they must be removed from the array. In other words, every time I click on the number 1, different random questions from the table should appear in the labels, but there should not be duplicates. Therefore, I want to remove them from the array immediately.

If I close the program and open it again, the arrays should be filled with questions automatically from the table.

How to create arrays for texts from a SQLite table that will be automatically updated?

Labels:

@FXML private Label lb_randomCard, lb_randomCardBack; 

    1 answer 1

    You need a List<Category> list, or Map<Integer, Category> may be more convenient. In the category object there are three fields corresponding to the table, the key for the card uses the ID . Fill the selected collection from the database in the same way that you retrieve data from the database, and then remove items from the collections.

    • I don't understand how to apply data from a table to the Map interface. Map has two parameters: a key and a value, but I have 3 parameters in the table: ID, question, answer. Can you give an example of using a map with one row from a table? - kentforth
    • map.put(id, new Category(id, question, answer)); - Maxim
    • thank! I will try) - kentforth