Advertisement
Guest User

zoeken

a guest
Jan 14th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. <Label fx:id="zoekLabel" layoutX="89.0" layoutY="571.0" text="Search" />
  2.     <TextField id="zoekterm" fx:id="zoekTerm" layoutX="152.0" layoutY="568.0" prefWidth="416.0" promptText="Search Term" />
  3.     <Button id="zoekButton" fx:id="zoekKnop" layoutX="598.0" layoutY="565.0" mnemonicParsing="false" onAction="#zoeken" text="Search" />
  4.  
  5. private void zoekDatabase(String term) throws SQLException {
  6.         //TODO zoeken in database WHERE ... LIKE '%zoekterm%' en toont lsitview op scherm
  7.         try {
  8.             // Load the JDBC driver
  9.             Class.forName("com.mysql.jdbc.Driver");
  10.             // Connect to a database
  11.             Connection c = DriverManager.getConnection("jdbc:mysql://localhost/corendon", "root", "Sql281092!");
  12.             Statement statement = c.createStatement();
  13.             // Execute a statement
  14.             ResultSet resultSet = statement.executeQuery("SELECT * FROM corendon.users WHERE Email LIKE '%" +term+ "%' OR UserRole LIKE '%" +term+ "%'");
  15.             listView.getItems().add("ID\t\tEmail\t\t\t\tRole");
  16.             while (resultSet.next()) {
  17.                 listView.getItems().add(resultSet.getInt(1) + "\t" + "\t"
  18.                         + resultSet.getString(2) + "\t" + "\t" + resultSet.getString(4));
  19.             }
  20.             // Close the connection
  21.             c.close();
  22.         } catch (ClassNotFoundException e) {
  23.         }
  24.     }
  25.  
  26.     @FXML
  27.     private void zoeken(ActionEvent event) throws IOException, SQLException {
  28.         listView.getItems().clear();
  29.         String term = zoekTerm.getText();
  30.         zoekDatabase(term);
  31.  
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement