public List<Cocinero> getAllCocinero() { List ll = new LinkedList(); Statement st; ResultSet rs; String url = "jdbc:mysql://localhost:3306/food"; String user = "******"; String pass = "******"; String driver = "com.mysql.jdbc.Driver"; try (Connection connection = DriverManager.getConnection(url, user, pass)) { Class.forName(driver); st = connection.createStatement(); String recordQuery = ("Select * from cocinero"); rs = st.executeQuery(recordQuery); while (rs.next()) { Integer idcoc = rs.getInt("idCocinero"); String years = rs.getString("AñosServicio"); String idemp = rs.getString("Empleados_idEmpleados"); Integer idepp = Integer.parseInt(idemp); ll.add(new Cocinero(idcoc, years, idepp)); } } catch (ClassNotFoundException | SQLException ex) { Logger.getLogger(MenuEmpleados.class.getName()).log(Level.SEVERE, null, ex); } return ll; }
// Method for fetching all stores to drop down menu public void getStores() { // Local variables ResultSet rs; Statement stmt; String query = "SELECT namn FROM Butik ORDER BY namn ASC"; try { stmt = con.createStatement(); rs = stmt.executeQuery(query); while (rs.next()) { choiceBox2.getItems().add(rs.getString("namn")); } stmt.close(); } catch (Exception e) { e.printStackTrace(); System.out.println("Error fetching data"); } }
// Method for displaying all available product types public void createStatement() { data = FXCollections.observableArrayList(); // Local variables ResultSet rs; Statement stmt; String query = "SELECT namn FROM Produktgrupp ORDER BY namn ASC"; try { stmt = con.createStatement(); rs = stmt.executeQuery(query); // Clearing tables of old data tableview.getItems().clear(); tableview.getColumns().clear(); // Table columns added dynamically using ResultSet metadata. for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) { // We are using non property style for making dynamic table final int j = i; TableColumn col = new TableColumn(rs.getMetaData().getColumnName(i + 1)); col.setCellValueFactory( new Callback< TableColumn.CellDataFeatures<ObservableList, String>, ObservableValue<String>>() { public ObservableValue<String> call( TableColumn.CellDataFeatures<ObservableList, String> param) { return new SimpleStringProperty(param.getValue().get(j).toString()); } }); tableview.getColumns().addAll(col); System.out.println("Column [" + i + "] "); } // Data added to ObservableList while (rs.next()) { // Iterate Row ObservableList<String> row = FXCollections.observableArrayList(); for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { // Iterate Column row.add(rs.getString(i)); } data.add(row); } // Data added to TableView tableview.setItems(data); // Close the variable stmt and release all resources bound to it // Any ResultSet associated to the Statement will be automatically closed too. stmt.close(); } catch (Exception e) { e.printStackTrace(); System.out.println("Error on Building Data"); } }
public List<Empleado> getAllEmpleados() { List ll = new LinkedList(); Statement st; ResultSet rs; String url = "jdbc:mysql://localhost:3306/food"; String user = "******"; String pass = "******"; String driver = "com.mysql.jdbc.Driver"; try (Connection connection = DriverManager.getConnection(url, user, pass)) { Class.forName(driver); st = connection.createStatement(); String recordQuery = ("Select * from empleados"); rs = st.executeQuery(recordQuery); while (rs.next()) { Integer id = rs.getInt("idEmpleados"); String name = rs.getString("Nombre"); String telf = rs.getString("Telefono"); ll.add(new Empleado(id, name, telf)); /// System.out.println(id +","+ name +","+ apellido +","+ cedula +","+ telf +" // "+direccion+""); } } catch (ClassNotFoundException | SQLException ex) { Logger.getLogger(MenuEmpleados.class.getName()).log(Level.SEVERE, null, ex); } return ll; }