String sql_query = "SELECT * FROM words";
ResultSet rs = statement_object.executeQuery(sql_query);
List<String> wordsList = new ArrayList<>();
int size = wordsList.size();
System.out.println("Enter the number of words you want to sort");
int numWords = input.nextInt();
int j4 = 0;
while (rs.next()) {
String words = rs.getString("Word");
words = words.toLowerCase();
dictionaryWords.add(words);
j4++;
for (int i = 0; i < numWords; i++) {
String [] randomWords = new String[numWords];
Random rand = new Random();
System.out.println(words);
}
}
The code prints the words in my database repetitively. For example,
Enter the number of words you want to sort: 3
Ape
Ape
Ape
Rose
Rose
Rose
Bite
Bite
Bite
I need it to print to pull 3 random words from the database (or whatever given input) and print that result. For example, Enter the number of words you want to sort: 3
Ape
Rose
Bite