Skip to content

blairw/javafx-planets-dbdemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

javafx-planets-dbdemo

This is a very simple demo of how to work with a SQLite database in a JavaFX setting.

Running it yourself

The codebase runs fine on both macOS and Windows. Please ensure that you Clean and Build in NetBeans before attempting to run.

Significant files

  1. App.java - JavaFX main class.
  2. DatabaseManager.java - helper class to manage the SQLite JDBC connection so that no other class has to.
  3. Planet.java - MVC "model" class.
  4. primary.fxml - MVC "view" file.
  5. PrimaryController.java - MVC "controller" class.

Significant parts of DatabaseManager.java

  1. openConnection() and closeConnection() are just convenient wrappers around the JDBC open/close connection cycle.
  2. createTheOnlyTableWeNeed() and setupDummyData() perform the two steps required for initial setup. The first one uses a Statement and the second one uses multiple instances of PreparedStatement, so they are a great demonstration of the difference between the two. They are only used if required, by...
  3. setupDatabaseOnFirstRun(), which first checks if the database is already there. This is called from App.java right after the GUI is launched.
  4. fetchPlanetByName(...), the method invoked by the GUI when the user clicks the Retrieve Size button. This is called from PrimaryController.java as part of the handler for the button.

What does the program actually do?

  1. On first launch, we set up a database of planets and their sizes (see DatabaseManager.setupDatabaseOnFirstRun()).
  2. Users can type some text and attempt to retrieve the size for the planet of the same name.
  3. If the planet exists, they get the size (radius of planet in km).
  4. If the planet does not exist, the user is told that no data is available.

Good run

Bad run

See also

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages