Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void initialize(URL location, ResourceBundle resources) {
- ObservableList<String> items = FXCollections.observableArrayList(
- "Single", "Double", "Suite", "Family App");
- listView.getItems().addAll(items);
- System.out.println("-------- PostgreSQL "
- + "JDBC Connection Testing ------------");
- try {
- Class.forName("org.postgresql.Driver");
- } catch (ClassNotFoundException e) {
- System.out.println("Where is your PostgreSQL JDBC Driver? "
- + "Include in your library path!");
- e.printStackTrace();
- return;
- }
- System.out.println("PostgreSQL JDBC Driver Registered!");
- Connection connection = null;
- Statement stmt = null;
- try {
- connection = DriverManager.getConnection(
- "jdbc:postgresql://127.0.0.1:5432/BotanicGarden", "postgres",
- "password");
- } catch (SQLException e) {
- System.out.println("Connection Failed! Check output console");
- e.printStackTrace();
- return;
- }
- if (connection != null) {
- System.out.println("You made it, take control your database now!");
- String sql = "INSERT INTO public.Plant(plant_id, plant_details, plant_hierarchy_id, family_id) VALUES(?,?,?,?)";
- try {
- PreparedStatement pstmt = connection.prepareStatement(sql);
- pstmt.setInt(1, 1);
- pstmt.setString(2,"description");
- pstmt.setInt(3, 1);
- pstmt.setInt(4, 1);
- pstmt.executeUpdate();
- } catch (SQLException e) {
- System.out.println("Ooops, something go wrong");
- System.out.println( e.toString() );
- e.printStackTrace();
- }
- } else {
- System.out.println("Failed to make connection!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement