0

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);
    }
halfer
  • 19,824
  • 17
  • 99
  • 186
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Jun 20 '18 at 16:16
  • Aside: you mentioned "java scripting" in your question. Note that this is Java, not JavaScript - the two are entirely unrelated, so it's worth specifying the right one. In general, anything that requires a separate compilation stage, as Java does, is not regarded as a "script". – halfer Jun 20 '18 at 18:50

0 Answers0