Another common scenario is connecting an application to a database.
In this recipe, we will see how to create a JavaFX Desktop application with form and index buttons.
To continue with this recipe, NetBeans and the set of plugins that bundle JavaFX must be installed.
If unsure how to proceed, please refer to the recipe, Creating a JavaFX Project, specifically the Getting ready section.
We also need JavaDB Database running.
To do this:
We need to create a New Project:
Main.fx
. Main.fx
. derby.jar
and derbyclient.jar
.Save the file and click on Run the Main Project.
The JDBC Data Source is responsible for connecting/fetching/updating our database. This is done by executing SQL queries in the background.
These actions are transparent for the developer since the JDBC Data Source is responsible for abstracting all of the work and only lets the developer customize the settings through the GUI.
The Create SQL Query dialog is used in our case, to perform a selection of all of the entries from the Customer
table.
Different SQL queries could be used in conjunction with the Data Source Customizer, but as we only want to display the data, this is the query used in the recipe.
After configuring the connection to the Database, we will need to actually bind the connection to some component.
The Desktop Form
component is responsible for showing the data. When customizing it, we add as our Data Source the jdbcDataSource
, which we have configured with the Customer
table. This will provide the application with all the data, presented in a well-formatted manner.
For our app to work, we need to add the Java DB JARs otherwise the app won't behave correctly.
3.137.221.116