質問があるsqliteのデータベースがあります。各質問には、件名、質問、回答、およびレベルの列があります。現時点では、私は科目を尋ねることができ、テキストで私を印刷します。ただし、常に同じ質問が選択されます。問題の数学に属するランダムな質問を選択するにはどうすればよいですか? 私のコードは、現時点では次のようになります。sqliteデータベースの共通の特性を持つランダムなデータを1つ選択してください。
question = new TextField();
question.setPrefWidth(400.0);
question.setPrefHeight(70.0);
question.setStyle("-fx-font: 30 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");
startTestButton = new Button("START");
startTestButton.addEventHandler(ActionEvent.ACTION, (e)-> {
counterQuestions = nQTextField.getText();
System.out.println("Number of questions: " + counterQuestions);
try
{
String sql = "select * from Questions where Subject = ?";
PreparedStatement pst = connectionQuestions.prepareStatement(sql);
pst.setString(1,SsubjectTestField.getText());
ResultSet rs = pst.executeQuery();
if(rs.next())
{
question.setText(rs.getString("Question"));
}
else
{
System.out.println("No data for this subject");
}
}
catch(Exception a)
{
System.out.println(a);
}
primaryStage.setScene(sceneMathTest);
});
startTestButton.setPrefWidth(200.0);
startTestButton.setPrefHeight(50.0);
startTestButton.setStyle("-fx-font: 30 timesnewroman; -fx-base: #2EFE64; -fx-text-fill: black;");
createTestButtonPane.add(startTestButton,5,6);
私が使用fraseがある:、「件名=質問SELECT * FROM?」しかし*それらのすべてを意味しますが、それは常に同じものを選んでいます。
ありがとうございます。
ありがとうございました。非常に有用な –