Exemplo n.º 1
0
  public static void Persist(Watch_Tv obj, int i, int j)
      throws SQLException, ClassNotFoundException {
    Connection con = Conexao.getConnection();
    PreparedStatement ps =
        con.prepareStatement(
            "insert into resource(Device_idDevice,Type_) values (?,?)",
            Statement.RETURN_GENERATED_KEYS);

    ps.setInt(1, obj.getHead().getsTBDevice().getDevices().get(i).getIdDevice());
    ps.setString(
        2, obj.getHead().getsTBDevice().getDevices().get(i).getResources().get(j).getType());

    ps.executeUpdate();

    ResultSet rskey = null;
    rskey = ps.getGeneratedKeys();

    if (rskey != null && rskey.next()) {
      obj.getHead()
          .getsTBDevice()
          .getDevices()
          .get(i)
          .getResources()
          .get(j)
          .setIdResource(rskey.getInt(1));
    }

    ps.close();
    con.close();
  }
Exemplo n.º 2
0
 public void Persit(Watch_Tv watchTv) {
   try {
     watchTv
         .getHead()
         .getLocation()
         .setIdLocation(
             new LocationController().Search(watchTv.getHead().getLocation()).getIdLocation());
   } catch (Exception e) {
     new LocationController().Persist(watchTv);
     watchTv
         .getHead()
         .getLocation()
         .setIdLocation(
             new LocationController().Search(watchTv.getHead().getLocation()).getIdLocation());
   }
   try {
     watchTv
         .getHead()
         .getsTBDevice()
         .setIdSTB_Device(
             new STBDeviceController()
                 .Search(watchTv.getHead().getsTBDevice().getSerialNumber())
                 .getIdSTB_Device());
   } catch (Exception e) {
     new STBDeviceController().Persist(watchTv);
     watchTv
         .getHead()
         .getsTBDevice()
         .setIdSTB_Device(
             new STBDeviceController()
                 .Search(watchTv.getHead().getsTBDevice().getSerialNumber())
                 .getIdSTB_Device());
   }
   try {
     HeadDao.Persist(watchTv);
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }