Exemplo n.º 1
0
 // Frederik
 public Order getOrder(Connection conn, int oID) {
   Order o = null;
   String SQLString = "select * " + "from orders " + "where oid = ?";
   PreparedStatement statement = null;
   try {
     statement = conn.prepareStatement(SQLString);
     statement.setInt(1, oID);
     ResultSet rs = statement.executeQuery();
     if (rs.next()) {
       o = new Order(rs.getInt(1), rs.getInt(2), rs.getDate(3), rs.getDate(4));
       SQLString = "select * " + "from orderdetails " + "where oid = ?";
       statement = conn.prepareStatement(SQLString);
       statement.setInt(1, oID);
       rs = statement.executeQuery();
       while (rs.next()) {
         o.addDetail(new OrderDetail(rs.getInt(1), rs.getInt(2), rs.getInt(3)));
       }
     }
   } catch (SQLException ex) {
     System.out.println("Fail in OrderMapper - getOrder");
     System.out.println(ex.getMessage());
   }
   return o;
 }
Exemplo n.º 2
0
 // Kirstine, Charlotte og Frederik
 public ArrayList<Order> getOrders(Connection conn, String datoFra, String datoTil) {
   Order currentO = null;
   ArrayList<Order> ol = new ArrayList();
   String SQLString =
       "select * "
           + "from orders "
           + "where datofra between to_date(?,'dd-mon-yyyy') "
           + "and to_date(?,'dd-mon-yyyy')";
   PreparedStatement statement = null;
   try {
     statement = conn.prepareStatement(SQLString);
     statement.setString(1, datoFra);
     statement.setString(2, datoTil);
     ResultSet rs = statement.executeQuery();
     SQLString = "select * " + "from orderdetails " + "where oID = ?";
     statement = conn.prepareStatement(SQLString);
     ResultSet rs2;
     String SQLString2 = "select * " + "from installers " + "where oID = ?";
     PreparedStatement statement2 = conn.prepareStatement(SQLString2);
     ResultSet rs3;
     while (rs.next()) {
       currentO = new Order(rs.getInt(1), rs.getInt(2), rs.getDate(3), rs.getDate(4));
       statement.setInt(1, currentO.getOID());
       rs2 = statement.executeQuery();
       while (rs2.next()) {
         currentO.addDetail(new OrderDetail(rs2.getInt(1), rs2.getInt(2), rs2.getInt(3)));
       }
       statement2.setInt(1, currentO.getOID());
       rs3 = statement2.executeQuery();
       Calendar c = new GregorianCalendar();
       while (rs3.next()) {
         c.setTimeInMillis(rs3.getDate(3).getTime());
         String from =
             c.get(c.DAY_OF_MONTH)
                 + "-"
                 + c.get(c.MONTH)
                 + "-"
                 + c.get(c.YEAR)
                 + " "
                 + c.get(c.HOUR_OF_DAY)
                 + ":"
                 + c.get(c.MINUTE);
         c.setTimeInMillis(rs3.getDate(4).getTime());
         String to =
             c.get(c.DAY_OF_MONTH)
                 + "-"
                 + c.get(c.MONTH)
                 + "-"
                 + c.get(c.YEAR)
                 + " "
                 + c.get(c.HOUR_OF_DAY)
                 + ":"
                 + c.get(c.MINUTE);
         currentO.addInstaller(new Installer(rs3.getInt(1), rs3.getInt(2), from, to));
       }
       ol.add(currentO);
     }
   } catch (SQLException ex) {
     System.out.println("Fail in OrderMapper - getOrders");
     System.out.println(ex.getMessage());
   }
   return ol;
 }