### A first GUI sketch

So far all data records being written to the database server by our (toy) application are just hard-coded. In practice a GUI is being required allowing for entering data.

We now guide you to develop a first version of a simple GUI for this tasks. A more elaborate version will be presented in a follow-up exercise. The subsequent screen shot illustrates the intended application behaviour:

Based on your existing JavaFX GUI experience the subsequent GUI employs the Vaadin application framework. Suggested reading:

### Tip

Though a JDBC type 4 driver does not require Class.forName("...") Jetty's automatic restart feature may fail indicating lack of JDBC driver availability. A static initializer helps:

   static {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
...
}
}

No. 45

#### GUI for inserting Person data to a database server

Q:

Write a WEB GUI based application as being outlined in Figure 946, “A simple GUI to insert data into a database server. ”. You may proceed as follows:

1. Write a dummy GUI without any database functionality. Only present the two labels an input fields and the Insert button.

2. Add an java.awt.event.ActionListener which generates a SQL INSERT Statement when clicking the Insert button. Return this string to the user as being shown in the message window of Figure 946, “A simple GUI to insert data into a database server. ”.

You do not (yet) need a database connection. The message shown to the user is just a mock up making the GUI appear to be working.

3. Establish a java.sql.Connection to your favourite database server (providing a suitable table) and create a java.sql.Statement instance when launching your application. Use the latter in your java.awt.event.ActionListener to actually insert datasets into your database.

4. Provide problem hints database connection failure to the end user and more detailed log messages for debugging purposes.

A:

The included README.md contains hints with respect to starting this application.

Notice the separation of problem related messages:

  ...    } catch (SQLException ex) {
Notification.show("Failed to insert record, see log for details",
}
 General message to the end-user. Detailed message to the application developer being directed to the log file A1.log as being configured in log4j2.xml.