Я пытаюсь создать простую программу для извлечения данных из базы данных. Соединение успешно, но я получаю эту ошибку в консоли java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Connection Successful
файл конфигурации
public class Config {
public Connection connect() {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/appointment", "root", "");
System.out.println("Connection Successful");
} catch (Exception e) {
System.out.println("Connection unsuccessful");
System.out.println("" + e);
}
return con;
}
public static void main(String[] args) {
Config config = new Config();
Connection con = config.connect();
}
}
Вызов соединения с базой данных
public String readAppoinment() {
String output = "";
try {
Connection con = config.connect();
if (con == null) {
return "Error while connecting to the database for reading appoinment details.";
}
output = "<table border=\"1\"><tr><th>Appointment Id</th><th>Appointment Date</th><th>Appointment Venue</th><th>Doctor Assign</th><th>Patient Id</th>"
+ "<th>Actions</th>";
String query = "select * from appointment";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String appId = Integer.toString(rs.getInt("app_Id"));
String appDate = rs.getString("app_Date");
String appVenue = rs.getString("app_Venue");
String docId = Integer.toString(rs.getInt("app_Doctor_Id"));
String patientId = Integer.toString(rs.getInt("app_Patient_Id"));
Я получаю
Error while connecting to the database
В результате в браузере.