Я не вижу, есть ли ошибка, потому что приложение ничего не запрашивает.Я хочу получить значение из базы данных и поместить его в переменную, которая будет отображаться позже, когда мне это понадобится.
Я довольно новичок в программировании, я пытался смотреть учебные пособия, но я просто не могу понять, как некоторые вещи выполняются должным образом, так как у преподавателей свой подход к работе.
public void selectQuery(String input) throws SQLException {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String USERNAME = "root";
String PASSWORD = "root";
String CONN_STRING =
"jdbc:mysql://localhost:3306/javaddy?serverTimezone=UTC";
Connection connection =
DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
try {
String q = "SELECT Inquiry_answer,Inquiry_question FROM inquiries WHERE Inquiry_question = '" + input + "'";
Statement stmt = connection.createStatement();
ResultSet res = stmt.executeQuery(q);
String answer;
answer = res.getString("Inquiry_answer");
// /* there is no value returned here (I think) because after passing to
// bot method, it doesn't print anything */
bot(answer);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
} catch (ClassNotFoundException e) {
System.out.println("Could not find the database driver " + e.getMessage());
} catch (SQLException e) {
System.out.println("Could not connect to the database " + e.getMessage());
}
}
Я ожидаю получить значение из базы данных, но оно не возвращено.