I’m mostly a front end developer. I’m currently trying to work on being a full stack developer. I have created a front end javafx based GUI and a backend java application. The application opens and allows a user to add or edit patient data. The user can save it to a simple database. It’s very basic for the time being.
I’m trying to figure out a better solution to connecting the front end and back end. Currently I have some queries that are hard coded into the application that are updating user details. The queries are working just fine however there has to be a better solution to this.
For example – if a user wants to see all users in the database: the user clicks the dropdown and the usernames are displayed. To do this I did the following –
try {
connection = db.getDBConnection();
statement = connection.createStatement();
resultSet = statement.executeQuery("SELECT * FROM Patients");
while (resultSet.next()) {
listView.add((new IDiagnosisModel(
resultSet.getString("First Name"),
resultSet.getString("Last Name")
)));
}
patientsTable.setItems(listView);
} catch (Exception e) {
Then the update query:
IPatientModel iPatientModel = newDiagCodeTable.getSelectionModel().getSelectedItem();
String SQL = "UPDATE Patients SET "
+ "firstName= '" + iPatientModel+ "' WHERE patientID = '" + patientID.getText() + "'";
try {
connection = db.getDBConnection();
System.out.println("Connected to Database");
statement.executeUpdate(SQL);
System.out.println(SQL);
} catch (Exception e) {
throw new RuntimeException(e);
}
Is there a better solution to grabbing data from the backend than writing queries in your code? In the past I’ve done frontend work on web application and working with api’s to update data. Can the same be created and utilized with this project?