Ejemplo n.º 1
0
  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;
  }
Ejemplo n.º 2
0
 private Optional<DynamicTreeItem> findParentOfType(
     TreeItem<DbTreeValue> selectedItem, Class<DynamicTreeItem> class1) {
   if (selectedItem == null) {
     return Optional.empty();
   }
   if (class1.isAssignableFrom(selectedItem.getClass())) {
     return Optional.of((DynamicTreeItem) selectedItem);
   }
   return findParentOfType(selectedItem.getParent(), class1);
 }
Ejemplo n.º 3
0
  private void connectToDB() {
    String driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost/BoolaBoolaUniversity";
    String username = "******";
    String password = "******";

    // Connect to database
    try {
      Class.forName(driver);
      connection = DriverManager.getConnection(url, username, password);

      System.out.println("Connected to " + url);

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
  // Method for establishing a DB connection
  public void connect() {

    // Relative path to Access database, project can be run from anywhere.
    File dbfile = new File("Icooköp_v8.accdb");
    String relativepath = dbfile.getAbsolutePath();

    // Local Access DB static variables
    String URL = "jdbc:ucanaccess://" + relativepath;
    String driver = "net.ucanaccess.jdbc.UcanaccessDriver";
    try {
      // Register the driver with DriverManager
      Class.forName(driver);
      // Create a connection to the database
      con = DriverManager.getConnection(URL);
      // Set the auto commit of the connection to false.
      // An explicit commit will be required in order to accept
      // any changes done to the DB through this connection.
      con.setAutoCommit(false);
      // Some logging
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 5
-1
  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;
  }