This is a very simple demo of how to work with a SQLite database in a JavaFX setting.
The codebase runs fine on both macOS and Windows. Please ensure that you Clean and Build in NetBeans before attempting to run.
App.java
- JavaFX main class.DatabaseManager.java
- helper class to manage the SQLite JDBC connection so that no other class has to.Planet.java
- MVC "model" class.primary.fxml
- MVC "view" file.PrimaryController.java
- MVC "controller" class.
openConnection()
andcloseConnection()
are just convenient wrappers around the JDBC open/close connection cycle.createTheOnlyTableWeNeed()
andsetupDummyData()
perform the two steps required for initial setup. The first one uses aStatement
and the second one uses multiple instances ofPreparedStatement
, so they are a great demonstration of the difference between the two. They are only used if required, by...setupDatabaseOnFirstRun()
, which first checks if the database is already there. This is called fromApp.java
right after the GUI is launched.fetchPlanetByName(...)
, the method invoked by the GUI when the user clicks the Retrieve Size button. This is called fromPrimaryController.java
as part of the handler for the button.
- On first launch, we set up a database of planets and their sizes (see
DatabaseManager.setupDatabaseOnFirstRun()
). - Users can type some text and attempt to retrieve the size for the planet of the same name.
- If the planet exists, they get the size (radius of planet in km).
- If the planet does not exist, the user is told that no data is available.
- infs2605fxstarterkit, the template from which this project was built up.