Advertisement
Guest User

Untitled

a guest
Mar 29th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. @Override
  2. public void initialize(URL location, ResourceBundle resources) {
  3.  
  4. ObservableList<String> items = FXCollections.observableArrayList(
  5. "Single", "Double", "Suite", "Family App");
  6. listView.getItems().addAll(items);
  7.  
  8. System.out.println("-------- PostgreSQL "
  9. + "JDBC Connection Testing ------------");
  10.  
  11. try {
  12.  
  13. Class.forName("org.postgresql.Driver");
  14.  
  15. } catch (ClassNotFoundException e) {
  16.  
  17. System.out.println("Where is your PostgreSQL JDBC Driver? "
  18. + "Include in your library path!");
  19. e.printStackTrace();
  20. return;
  21.  
  22. }
  23.  
  24. System.out.println("PostgreSQL JDBC Driver Registered!");
  25.  
  26. Connection connection = null;
  27. Statement stmt = null;
  28.  
  29. try {
  30.  
  31. connection = DriverManager.getConnection(
  32. "jdbc:postgresql://127.0.0.1:5432/BotanicGarden", "postgres",
  33. "password");
  34.  
  35. } catch (SQLException e) {
  36.  
  37. System.out.println("Connection Failed! Check output console");
  38. e.printStackTrace();
  39. return;
  40.  
  41. }
  42.  
  43. if (connection != null) {
  44. System.out.println("You made it, take control your database now!");
  45. String sql = "INSERT INTO public.Plant(plant_id, plant_details, plant_hierarchy_id, family_id) VALUES(?,?,?,?)";
  46. try {
  47. PreparedStatement pstmt = connection.prepareStatement(sql);
  48. pstmt.setInt(1, 1);
  49. pstmt.setString(2,"description");
  50. pstmt.setInt(3, 1);
  51. pstmt.setInt(4, 1);
  52. pstmt.executeUpdate();
  53. } catch (SQLException e) {
  54. System.out.println("Ooops, something go wrong");
  55. System.out.println( e.toString() );
  56. e.printStackTrace();
  57. }
  58. } else {
  59. System.out.println("Failed to make connection!");
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement