├── .classpath ├── .gitignore ├── .project ├── build.fxbuild ├── db.properties └── src ├── application ├── Main.java └── application.css ├── db ├── DB.java ├── DbException.java └── DbIntegrityException.java ├── gui ├── About.fxml ├── DepartmentForm.fxml ├── DepartmentFormController.java ├── DepartmentList.fxml ├── DepartmentListController.java ├── MainView.fxml ├── MainViewController.java ├── SellerForm.fxml ├── SellerFormController.java ├── SellerList.fxml ├── SellerListController.java ├── listeners │ └── DataChangeListener.java └── util │ ├── Alerts.java │ ├── Constraints.java │ └── Utils.java └── model ├── dao ├── DaoFactory.java ├── DepartmentDao.java ├── SellerDao.java └── impl │ ├── DepartmentDaoJDBC.java │ └── SellerDaoJDBC.java ├── entities ├── Department.java └── Seller.java ├── exceptions └── ValidationException.java └── services ├── DepartmentService.java └── SellerService.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | # build folders 26 | bin/ 27 | target/ 28 | nbproject/private/ 29 | build/ 30 | nbbuild/ 31 | dist/ 32 | nbdist/ 33 | 34 | # Eclipse 35 | .settings/ 36 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | workshop-javafx-jdbc 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.xtext.ui.shared.xtextBuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.xtext.ui.shared.xtextNature 21 | org.eclipse.jdt.core.javanature 22 | 23 | 24 | -------------------------------------------------------------------------------- /build.fxbuild: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /db.properties: -------------------------------------------------------------------------------- 1 | user=developer 2 | password=1234567 3 | dburl=jdbc:mysql://localhost:3306/coursejdbc 4 | useSSL=false 5 | -------------------------------------------------------------------------------- /src/application/Main.java: -------------------------------------------------------------------------------- 1 | package application; 2 | 3 | import java.io.IOException; 4 | 5 | import javafx.application.Application; 6 | import javafx.fxml.FXMLLoader; 7 | import javafx.scene.Scene; 8 | import javafx.scene.control.ScrollPane; 9 | import javafx.stage.Stage; 10 | 11 | public class Main extends Application { 12 | 13 | private static Scene mainScene; 14 | 15 | @Override 16 | public void start(Stage primaryStage) { 17 | try { 18 | FXMLLoader loader = new FXMLLoader(getClass().getResource("/gui/MainView.fxml")); 19 | ScrollPane scrollPane = loader.load(); 20 | 21 | scrollPane.setFitToHeight(true); 22 | scrollPane.setFitToWidth(true); 23 | 24 | mainScene = new Scene(scrollPane); 25 | primaryStage.setScene(mainScene); 26 | primaryStage.setTitle("Sample JavaFX application"); 27 | primaryStage.show(); 28 | } catch (IOException e) { 29 | e.printStackTrace(); 30 | } 31 | } 32 | 33 | public static Scene getMainScene() { 34 | return mainScene; 35 | } 36 | 37 | public static void main(String[] args) { 38 | launch(args); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/application/application.css: -------------------------------------------------------------------------------- 1 | /* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */ -------------------------------------------------------------------------------- /src/db/DB.java: -------------------------------------------------------------------------------- 1 | package db; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.IOException; 5 | import java.sql.Connection; 6 | import java.sql.DriverManager; 7 | import java.sql.ResultSet; 8 | import java.sql.SQLException; 9 | import java.sql.Statement; 10 | import java.util.Properties; 11 | 12 | public class DB { 13 | 14 | private static Connection conn = null; 15 | 16 | public static Connection getConnection() { 17 | if (conn == null) { 18 | try { 19 | Properties props = loadProperties(); 20 | String url = props.getProperty("dburl"); 21 | conn = DriverManager.getConnection(url, props); 22 | } 23 | catch (SQLException e) { 24 | throw new DbException(e.getMessage()); 25 | } 26 | } 27 | return conn; 28 | } 29 | 30 | public static void closeConnection() { 31 | if (conn != null) { 32 | try { 33 | conn.close(); 34 | } catch (SQLException e) { 35 | throw new DbException(e.getMessage()); 36 | } 37 | } 38 | } 39 | 40 | private static Properties loadProperties() { 41 | try (FileInputStream fs = new FileInputStream("db.properties")) { 42 | Properties props = new Properties(); 43 | props.load(fs); 44 | return props; 45 | } 46 | catch (IOException e) { 47 | throw new DbException(e.getMessage()); 48 | } 49 | } 50 | 51 | public static void closeStatement(Statement st) { 52 | if (st != null) { 53 | try { 54 | st.close(); 55 | } catch (SQLException e) { 56 | throw new DbException(e.getMessage()); 57 | } 58 | } 59 | } 60 | 61 | public static void closeResultSet(ResultSet rs) { 62 | if (rs != null) { 63 | try { 64 | rs.close(); 65 | } catch (SQLException e) { 66 | throw new DbException(e.getMessage()); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/db/DbException.java: -------------------------------------------------------------------------------- 1 | package db; 2 | 3 | public class DbException extends RuntimeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public DbException(String msg) { 7 | super(msg); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/db/DbIntegrityException.java: -------------------------------------------------------------------------------- 1 | package db; 2 | 3 | public class DbIntegrityException extends RuntimeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public DbIntegrityException(String msg) { 7 | super(msg); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/gui/About.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 19 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/gui/DepartmentForm.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |