I'm new to JavaScript and have to build a jdbc application for school. I already have the database in Heidisql and made connection but I the error when I build it. I don't know what the next step is. I have created an arraylist. The error references line 25 in the repository code.
public class TechnicianRepository {
private Connection connection;
public TechnicianRepository() {
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("De Driver is geregistreerd!");
String URL = "jdbc:mysql://localhost/atm_installatie";
String USER = "root";
String PASS = "Br@h!em8891";
Connection conn = DriverManager.getConnection(URL, USER, PASS);
System.out.println(connection);
System.out.println();
} catch (ClassNotFoundException ex) {
System.out.println("Error: unable to load driver class!");
System.exit(1);
} catch (SQLException e) {
e.printStackTrace();
}
}
public List<Technician> findAllRecords() {
List<Technician> technicianList = new ArrayList<Technician>();
Statement stmt = null;
try {
stmt = connection.createStatement();
String sql = "SELECT * FROM Technician";
ResultSet rs = stmt.executeQuery(sql);
System.out.println("Resultset: " + rs);
while (rs.next()) {
int tech_id = rs.getInt("tech_id");
String voornaam = rs.getString("voornaam");
String achternaam = rs.getString("achternaam");
String functie = rs.getString("functie");
String email_adres = rs.getString("email_adres");
String telefoonnummer = rs.getString("telefoonnummer");
System.out.println("Tech_ID: " + tech_id);
System.out.println("Voornaam: " + voornaam);
System.out.println("Achternaam: " + achternaam);
System.out.println("Functie: " + functie);
System.out.println("Email_Adres: " + email_adres);
System.out.println("TelefoonNummer: " + telefoonnummer);
technicianList.add(new Technician(tech_id, voornaam, achternaam, functie, email_adres, telefoonnummer));
technicianList.add(new Technician(rs.getInt("tech_id"), rs.getString("voornaam"), rs.getString("achternaam"), rs.getString("functie"), rs.getString("email_adres"), rs.getString("telefoonnummer")));
}
rs.close();
} catch (SQLException e) {
} finally {
//if (stmt != null) { stmt.close(); }
}
return technicianList;
}
public class Applicatie {
public static void main(String[] args) {
TechnicianRepository technicianrepo = new TechnicianRepository();
List<Technician> technicianList = technicianrepo.findAllRecords();
for (Technician technician : technicianList) {
System.out.println(technician);
}