Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Label fx:id="zoekLabel" layoutX="89.0" layoutY="571.0" text="Search" />
- <TextField id="zoekterm" fx:id="zoekTerm" layoutX="152.0" layoutY="568.0" prefWidth="416.0" promptText="Search Term" />
- <Button id="zoekButton" fx:id="zoekKnop" layoutX="598.0" layoutY="565.0" mnemonicParsing="false" onAction="#zoeken" text="Search" />
- private void zoekDatabase(String term) throws SQLException {
- //TODO zoeken in database WHERE ... LIKE '%zoekterm%' en toont lsitview op scherm
- try {
- // Load the JDBC driver
- Class.forName("com.mysql.jdbc.Driver");
- // Connect to a database
- Connection c = DriverManager.getConnection("jdbc:mysql://localhost/corendon", "root", "Sql281092!");
- Statement statement = c.createStatement();
- // Execute a statement
- ResultSet resultSet = statement.executeQuery("SELECT * FROM corendon.users WHERE Email LIKE '%" +term+ "%' OR UserRole LIKE '%" +term+ "%'");
- listView.getItems().add("ID\t\tEmail\t\t\t\tRole");
- while (resultSet.next()) {
- listView.getItems().add(resultSet.getInt(1) + "\t" + "\t"
- + resultSet.getString(2) + "\t" + "\t" + resultSet.getString(4));
- }
- // Close the connection
- c.close();
- } catch (ClassNotFoundException e) {
- }
- }
- @FXML
- private void zoeken(ActionEvent event) throws IOException, SQLException {
- listView.getItems().clear();
- String term = zoekTerm.getText();
- zoekDatabase(term);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement