I'm passing my method InsertQuery variables from another method which are entered by the user via Scanner.
How do I fill in the iName, iType etc. into my iQuery so that I can insert them into my DB?
public void InsertQuery (String iName, String iType, int health_Problem, Date date2, String aRemind, String docName, String docType, String docAdress) { final String url = "jdbc:mysql://localhost/ehealthdb?serverTimezone=UTC"; final String DBUSER = "root"; final String DBPSWD = "root"; try { Connection con = DriverManager.getConnection(url,DBUSER,DBPSWD); Statement stmt = con.createStatement(); String iQuery = "INSERT into appointment" + "(ID, PatientID, Insurance_Name, Insurance_Type, Health_Problem, Appointment_Date, Appointment_Remind, Doctor_Name,Doctor_Type,Doctor_Adress)" + "values ('1','1',,'Gesetzlich','5','15.01.2020','1 Week','Musterarzt','Hausarzt','Musterstraße')"; stmt.executeUpdate(iQuery); } catch (Exception e) { System.out.println("Something went wrong @InsertQuery"); } }
Dateis a terrible class that was supplanted years ago by the modern java.time classes defined in JSR 310. Furthermore, appointments should be represented not as a moment, in case politicians change time zone's offset. Better to storeLocalDateTimeviaPreparedStatement#setObject, andZoneIdas text.