public synchronized void updateThumbnail(
     String name, long modified, int type, DLNAMediaInfo media) {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = getConnection();
     ps = conn.prepareStatement("UPDATE FILES SET THUMB = ? WHERE FILENAME = ? AND MODIFIED = ?");
     ps.setString(2, name);
     ps.setTimestamp(3, new Timestamp(modified));
     if (media != null) {
       ps.setBytes(1, media.getThumb());
     } else {
       ps.setNull(1, Types.BINARY);
     }
     ps.executeUpdate();
   } catch (SQLException se) {
     if (se.getErrorCode() == 23001) {
       LOGGER.debug(
           "Duplicate key while inserting this entry: "
               + name
               + " into the database: "
               + se.getMessage());
     } else {
       LOGGER.error(null, se);
     }
   } finally {
     close(ps);
     close(conn);
   }
 }
Exemplo n.º 2
0
  public void excluirLote(List<JobLote> listaExcluir) {

    Connection conn = null;
    PreparedStatement stmt = null;
    String sql = "delete from joblote where job = ? and operacao = ? and lote =? ";

    try {

      conn = GerenciaConexaoSQLServer.abreConexao();
      conn.setAutoCommit(false);

      for (int i = 0; i <= listaExcluir.size() - 1; i++) {

        JobLote job = listaExcluir.get(i);

        stmt = conn.prepareStatement(sql);
        stmt.setString(1, job.getJob().trim().replace(".", ""));
        stmt.setInt(2, job.getOperNum());
        stmt.setInt(3, job.getLote());
        stmt.executeUpdate();

        alteraJobAposExclusao(conn, job);

        gravaJobsExcluidos(
            conn, job.getJob().trim().replace(".", ""), job.getOperNum(), job.getLote());
      }

      // adiciona a op na tela inicial
      for (int i = 0; i <= listaExcluir.size() - 1; i++) {
        JobLote job = listaExcluir.get(i);
        JobProtheus jobProtheus = retornaJob(conn, job);
        adicionaOPTelaInicial(conn, jobProtheus, job);
      }

      JOptionPane.showMessageDialog(this, "Job Excluido com Sucesso!");
      conn.commit();

    } catch (SQLException e) {

      if (conn != null) {

        try {

          conn.rollback();
          conn.setAutoCommit(true);

          JOptionPane.showMessageDialog(null, "Não foi possivel excluir! Descrição: " + e);

        } catch (SQLException ex) {
          JOptionPane.showMessageDialog(null, "Erro ao fazer o rollback! Descrição: " + ex);
        }
      }

    } finally {
      GerenciaConexaoSQLServer.closeConexao(conn, stmt);
    }
  }
Exemplo n.º 3
0
  public void desativaIniciado(Connection conn, String op, int operacao) throws SQLException {

    String sql = "update jobsiniciados set ativo = 0 where job = ? and operacao = ? ";
    PreparedStatement stmt = null;

    stmt = conn.prepareStatement(sql);
    stmt.setString(1, op.trim().replace(".", ""));
    stmt.setInt(2, operacao);
    stmt.executeUpdate();
  }
Exemplo n.º 4
0
  public void gravaJobsExcluidos(Connection conn, String job, int operacao, int lote)
      throws SQLException {

    PreparedStatement stmt = null;
    String insert = "insert into joblotesexcluidos (job, operacao, lote) values (?,?,?)";

    stmt = conn.prepareStatement(insert);
    stmt.setString(1, job.trim());
    stmt.setInt(2, operacao);
    stmt.setInt(3, lote);
    stmt.executeUpdate();
  }
Exemplo n.º 5
0
  public void incluiIniciado(Connection conn, JobIniciado job) throws SQLException {

    String sql =
        "insert into jobsiniciados(job, operacao, data, tripulacao, ativo, recurso) values(?,?,?,?,?,?) ";
    PreparedStatement stmt = null;

    stmt = conn.prepareStatement(sql);
    stmt.setString(1, job.getJob().trim().replace(".", ""));
    stmt.setInt(2, job.getOperacao());
    stmt.setTimestamp(3, Validacoes.converteDataStringEmFormatoTimeStamp(job.getData().trim()));
    stmt.setDouble(4, job.getTripulacao());
    stmt.setBoolean(5, true);
    stmt.setString(6, job.getRecurso().trim());
    stmt.executeUpdate();
  }
Exemplo n.º 6
0
  public void alteraJobAposExclusao(Connection conn, JobLote job) throws SQLException {

    ValoresAtualizaJob valores = retornaNovosValores(conn, job);

    PreparedStatement stmt = null;
    String update =
        "update job set qtd_transf = ?, hr_tot = ?, qtd_sucata = ?, status = ? where job = ? and operacao = ? ";

    stmt = conn.prepareStatement(update);
    stmt.setDouble(1, valores.getQtdTransf());
    stmt.setDouble(2, valores.getHoraTotal());
    stmt.setDouble(3, valores.getQtdSucata());
    stmt.setString(4, "R");
    stmt.setString(5, job.getJob().trim().replace(".", ""));
    stmt.setInt(6, job.getOperNum());
    stmt.executeUpdate();
  }
Exemplo n.º 7
0
  public void alteraIniciado(Connection conn, JobIniciado job) throws SQLException {

    String sql =
        " update jobsiniciados set data = ?, ativo = ?, tripulacao = ?, recurso = ?  "
            + "    where job = ? and operacao = ? ";
    PreparedStatement stmt = null;

    stmt = conn.prepareStatement(sql);

    stmt.setTimestamp(1, Validacoes.converteDataStringEmFormatoTimeStamp(job.getData().trim()));
    stmt.setBoolean(2, true);
    stmt.setDouble(3, job.getTripulacao());
    stmt.setString(4, job.getRecurso().trim());
    stmt.setString(5, job.getJob().trim().replace(".", ""));
    stmt.setInt(6, job.getOperacao());
    stmt.executeUpdate();
  }
Exemplo n.º 8
0
  // event handling
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btnok) {
      PreparedStatement pstm;
      ResultSet rs;
      String sql;
      // if no entries has been made and hit ok button throw an error
      // you can do this step using try clause as well
      if ((tf1.getText().equals("") && (tf2.getText().equals("")))) {
        lblmsg.setText("Enter your details ");
        lblmsg.setForeground(Color.magenta);
      } else {

        try {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          Connection connect = DriverManager.getConnection("jdbc:odbc:student_base");
          System.out.println("Connected to the database");
          pstm = connect.prepareStatement("insert into student_base values(?,?)");
          pstm.setString(1, tf1.getText());
          pstm.setString(2, tf2.getText());
          // execute method to execute the query
          pstm.executeUpdate();
          lblmsg.setText("Details have been added to database");

          // closing the prepared statement  and connection object
          pstm.close();
          connect.close();
        } catch (SQLException sqe) {
          System.out.println("SQl error");
        } catch (ClassNotFoundException cnf) {
          System.out.println("Class not found error");
        }
      }
    }
    // upon clickin button addnew , your textfield will be empty to enternext record
    if (e.getSource() == btnaddnew) {
      tf1.setText("");
      tf2.setText("");
    }

    if (e.getSource() == btnexit) {
      System.exit(1);
    }
  }
  public static void add(String a, String b, File x, String s) throws Exception {
    fis = new FileInputStream(x);

    pa.setString(1, "" + dt);
    pa.setInt(2, pid);
    pa.setString(3, pfnm);
    pa.setString(4, pmnm);
    pa.setString(5, plnm);
    pa.setString(6, gen);
    pa.setInt(7, age);
    pa.setString(8, wt);
    pa.setString(9, a);
    pa.setString(10, cno);
    pa.setString(11, dnm);
    pa.setString(12, b);
    pa.setString(13, dig);
    pa.setInt(14, fee);
    pa.setString(15, bg);
    pa.setString(17, s);
    pa.setBinaryStream(16, (InputStream) fis, (int) (x.length()));

    pa.executeUpdate();
  }
  public static void mod(File x, String s) throws Exception {

    try {
      System.out.println(x);
      fis = new FileInputStream(x);
      // tmp=con.prepareStatement("update patient set
      // dt=?,pfnm=?,pmnm=?,plnm=?,gen=?,age=?,wt=?,addr=?,cno=?,dnnm=?,sym=?,dig=?,fee=? where
      // pid=1");
      tmp =
          con.prepareStatement(
              "update patient set dt=?,pfnm=?,pmnm=?,plnm=?,gen=?,age=?,wt=?,addr=?,cno=?,dnm=?,sym=?,dig=?,fee=?,bg=?,i=?,path=? where pid="
                  + pid);
      // tmp.setString(1,pfnm);
      tmp.setString(1, "" + dt);
      tmp.setString(2, pfnm);
      tmp.setString(3, pmnm);
      tmp.setString(4, plnm);
      tmp.setString(5, gen);
      tmp.setInt(6, age);
      tmp.setString(7, wt);
      tmp.setString(8, addr);
      tmp.setString(9, cno);
      tmp.setString(10, dnm);
      tmp.setString(11, sym);
      tmp.setString(12, dig);
      tmp.setInt(13, fee);
      tmp.setString(14, bg);

      tmp.setString(16, s);
      tmp.setBinaryStream(15, (InputStream) fis, (int) (x.length()));

      tmp.executeUpdate();
    } catch (Exception ee) {
      System.out.println("mod123 " + ee);
    }
  }
 public static void del() throws Exception {
   pd.setInt(1, pid);
   pd.executeUpdate();
 }
Exemplo n.º 12
0
  public synchronized void insertData(String name, long modified, int type, DLNAMediaInfo media) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
      conn = getConnection();
      ps =
          conn.prepareStatement(
              "INSERT INTO FILES(FILENAME, MODIFIED, TYPE, DURATION, BITRATE, WIDTH, HEIGHT, SIZE, CODECV, FRAMERATE, ASPECT, ASPECTRATIOCONTAINER, ASPECTRATIOVIDEOTRACK, REFRAMES, AVCLEVEL, BITSPERPIXEL, THUMB, CONTAINER, MODEL, EXPOSURE, ORIENTATION, ISO, MUXINGMODE, FRAMERATEMODE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
      ps.setString(1, name);
      ps.setTimestamp(2, new Timestamp(modified));
      ps.setInt(3, type);
      if (media != null) {
        if (media.getDuration() != null) {
          ps.setDouble(4, media.getDurationInSeconds());
        } else {
          ps.setNull(4, Types.DOUBLE);
        }

        int databaseBitrate = 0;
        if (type != Format.IMAGE) {
          databaseBitrate = media.getBitrate();
          if (databaseBitrate == 0) {
            LOGGER.debug("Could not parse the bitrate from: " + name);
          }
        }
        ps.setInt(5, databaseBitrate);

        ps.setInt(6, media.getWidth());
        ps.setInt(7, media.getHeight());
        ps.setLong(8, media.getSize());
        ps.setString(9, left(media.getCodecV(), SIZE_CODECV));
        ps.setString(10, left(media.getFrameRate(), SIZE_FRAMERATE));
        ps.setString(11, left(media.getAspect(), SIZE_ASPECT));
        ps.setString(12, left(media.getAspect(), SIZE_ASPECTRATIO_CONTAINER));
        ps.setString(13, left(media.getAspect(), SIZE_ASPECTRATIO_VIDEOTRACK));
        ps.setByte(14, media.getReferenceFrameCount());
        ps.setString(15, left(media.getAvcLevel(), SIZE_AVC_LEVEL));
        ps.setInt(16, media.getBitsPerPixel());
        ps.setBytes(17, media.getThumb());
        ps.setString(18, left(media.getContainer(), SIZE_CONTAINER));
        if (media.getExtras() != null) {
          ps.setString(19, left(media.getExtrasAsString(), SIZE_MODEL));
        } else {
          ps.setString(19, left(media.getModel(), SIZE_MODEL));
        }
        ps.setInt(20, media.getExposure());
        ps.setInt(21, media.getOrientation());
        ps.setInt(22, media.getIso());
        ps.setString(23, left(media.getMuxingModeAudio(), SIZE_MUXINGMODE));
        ps.setString(24, left(media.getFrameRateMode(), SIZE_FRAMERATE_MODE));
      } else {
        ps.setString(4, null);
        ps.setInt(5, 0);
        ps.setInt(6, 0);
        ps.setInt(7, 0);
        ps.setLong(8, 0);
        ps.setString(9, null);
        ps.setString(10, null);
        ps.setString(11, null);
        ps.setString(12, null);
        ps.setString(13, null);
        ps.setByte(14, (byte) -1);
        ps.setString(15, null);
        ps.setInt(16, 0);
        ps.setBytes(17, null);
        ps.setString(18, null);
        ps.setString(19, null);
        ps.setInt(20, 0);
        ps.setInt(21, 0);
        ps.setInt(22, 0);
        ps.setString(23, null);
        ps.setString(24, null);
      }
      ps.executeUpdate();
      ResultSet rs = ps.getGeneratedKeys();
      int id = -1;
      while (rs.next()) {
        id = rs.getInt(1);
      }
      rs.close();
      if (media != null && id > -1) {
        PreparedStatement insert = null;
        if (media.getAudioTracksList().size() > 0) {
          insert =
              conn.prepareStatement(
                  "INSERT INTO AUDIOTRACKS VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
        }

        for (DLNAMediaAudio audio : media.getAudioTracksList()) {
          insert.clearParameters();
          insert.setInt(1, id);
          insert.setInt(2, audio.getId());
          insert.setString(3, left(audio.getLang(), SIZE_LANG));
          insert.setString(4, left(audio.getFlavor(), SIZE_FLAVOR));
          insert.setInt(5, audio.getAudioProperties().getNumberOfChannels());
          insert.setString(6, left(audio.getSampleFrequency(), SIZE_SAMPLEFREQ));
          insert.setString(7, left(audio.getCodecA(), SIZE_CODECA));
          insert.setInt(8, audio.getBitsperSample());
          insert.setString(9, left(trimToEmpty(audio.getAlbum()), SIZE_ALBUM));
          insert.setString(10, left(trimToEmpty(audio.getArtist()), SIZE_ARTIST));
          insert.setString(11, left(trimToEmpty(audio.getSongname()), SIZE_SONGNAME));
          insert.setString(12, left(trimToEmpty(audio.getGenre()), SIZE_GENRE));
          insert.setInt(13, audio.getYear());
          insert.setInt(14, audio.getTrack());
          insert.setInt(15, audio.getAudioProperties().getAudioDelay());
          insert.setString(16, left(trimToEmpty(audio.getMuxingModeAudio()), SIZE_MUXINGMODE));
          insert.setInt(17, audio.getBitRate());

          try {
            insert.executeUpdate();
          } catch (JdbcSQLException e) {
            if (e.getErrorCode() == 23505) {
              LOGGER.debug(
                  "A duplicate key error occurred while trying to store the following file's audio information in the database: "
                      + name);
            } else {
              LOGGER.debug(
                  "An error occurred while trying to store the following file's audio information in the database: "
                      + name);
            }
            LOGGER.debug("The error given by jdbc was: " + e);
          }
        }

        if (media.getSubtitleTracksList().size() > 0) {
          insert = conn.prepareStatement("INSERT INTO SUBTRACKS VALUES (?, ?, ?, ?, ?)");
        }
        for (DLNAMediaSubtitle sub : media.getSubtitleTracksList()) {
          if (sub.getExternalFile() == null) { // no save of external subtitles
            insert.clearParameters();
            insert.setInt(1, id);
            insert.setInt(2, sub.getId());
            insert.setString(3, left(sub.getLang(), SIZE_LANG));
            insert.setString(4, left(sub.getFlavor(), SIZE_FLAVOR));
            insert.setInt(5, sub.getType().getStableIndex());
            try {
              insert.executeUpdate();
            } catch (JdbcSQLException e) {
              if (e.getErrorCode() == 23505) {
                LOGGER.debug(
                    "A duplicate key error occurred while trying to store the following file's subtitle information in the database: "
                        + name);
              } else {
                LOGGER.debug(
                    "An error occurred while trying to store the following file's subtitle information in the database: "
                        + name);
              }
              LOGGER.debug("The error given by jdbc was: " + e);
            }
          }
        }
        close(insert);
      }
    } catch (SQLException se) {
      if (se.getErrorCode() == 23001) {
        LOGGER.debug(
            "Duplicate key while inserting this entry: "
                + name
                + " into the database: "
                + se.getMessage());
      } else {
        LOGGER.error(null, se);
      }
    } finally {
      close(ps);
      close(conn);
    }
  }
    public void actionPerformed(ActionEvent ae) {
      try {

        Integer num1 = Integer.parseInt(tfdid.getText());
        if (num1.equals(null)) {
          System.out.println("num");
          throw new BlankException();
        }

        String name1 = tfname.getText();
        int a;
        a = name1.charAt(0);
        if (name1.equals("") || a == 32) {
          throw new BlankException();
        } else {
          for (int i = 0; i < name1.length(); i++) {
            boolean check = Character.isLetter(name1.charAt(i));
            a = name1.charAt(i);
            System.out.print("  " + a);
            if (!((a >= 65 && a <= 90) || (a >= 97 && a <= 122) || (a == 32) || (a == 46))) {
              throw new NameEx();
            }
          }
        }

        String addr1 = taadd.getText();
        if (addr1.equals(null)) {
          System.out.println("addr");
          throw new BlankException();
        }

        String contact1 = tftel.getText();

        String spec1 = taspecial.getText();
        String workf1 = tfworkf.getText();
        String workt1 = tfworkt.getText();

        String str =
            "UPDATE DOC SET name=?,address=?,contact=?,specialization=?,workfrom=?,workto=? WHERE did=?";

        Statement st1 = cn.createStatement();

        PreparedStatement psmt = cn.prepareStatement(str);
        psmt.setString(1, name1);
        psmt.setString(2, addr1);
        psmt.setString(3, contact1);
        psmt.setString(4, spec1);
        psmt.setString(5, workf1);
        psmt.setString(6, workt1);
        psmt.setInt(7, num1);

        psmt.executeUpdate();

        JOptionPane.showMessageDialog(
            new JFrame(), "Data Modified successfully!", "Done!", JOptionPane.INFORMATION_MESSAGE);

      } catch (SQLException sq) {
        String message = "Enter Valid Doctor ID and Contact.";
        JOptionPane.showMessageDialog(new JFrame(), message, "ERROR!", JOptionPane.ERROR_MESSAGE);
        System.out.println(sq);
      } catch (BlankException be) {
        JOptionPane.showMessageDialog(
            new JFrame(), "Please Enter All The Fields", "ERROR!", JOptionPane.ERROR_MESSAGE);
      } catch (NumberFormatException nfe) {
        JOptionPane.showMessageDialog(
            new JFrame(),
            "Patient Number and Contact Number Must Contain Digits.",
            "ERROR!",
            JOptionPane.ERROR_MESSAGE);
      } catch (NameEx ne) {
        JOptionPane.showMessageDialog(
            new JFrame(), "Invalid Name", "ERROR!", JOptionPane.ERROR_MESSAGE);
      } catch (Exception e) {
        System.out.println(e);
        JOptionPane.showMessageDialog(
            new JFrame(), "Enter Valid Date", "Error", JOptionPane.ERROR_MESSAGE);
      }
    }
Exemplo n.º 14
0
  public void actionPerformed(ActionEvent ae) {

    String s1 = ae.getActionCommand();

    if (s1.equals("Calendar")) {
      // DatePicker dp=new DatePicker(f);
      // dp.displayDate();
      // f.getContentPane().add(p);

      b3.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
              t6.setText(new DatePicker(f).setPickedDate());
            }
          });

    } else if (s1.equals("LogOut")) {
      f.dispose();
      start p = new start();
      p.method();

    } else if (s1.equals("Search")) {

      try {
        String data = t1.getSelectedItem();
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:raman1");
        Statement stm = con.createStatement();
        ResultSet rs = stm.executeQuery("select * from mprofile  where Manager_Id='" + data + "' ");
        while (rs.next()) {
          String a2 = rs.getString(1);
          t2.setText(a2);
          String a3 = rs.getString(2);
          t3.setText(a3);
          String a4 = rs.getString(3);
          t4.setText(a4);

          String a5 = rs.getString(4);
          t5.setText(a5);

          String a6 = rs.getString(6);
          t6.setText(a6);

          String a7 = rs.getString(7);
          t7.setText(a7);

          String a8 = rs.getString(8);
          t8.setText(a8);

          String a9 = rs.getString(9);
          t9.setText(a9);

          String a10 = rs.getString(10);
          t10.setText(a10);

          p.add(l3);
          p.add(t2);
          p.add(l4);
          p.add(t3);
          p.add(l5);
          p.add(t4);
          p.add(l6);
          p.add(t5);
          p.add(l7);
          p.add(c1);
          p.add(c2);
          p.add(l8);
          p.add(t6);
          p.add(l9);
          p.add(t7);
          p.add(l10);
          p.add(t8);
          p.add(l11);
          p.add(t9);
          p.add(l12);
          p.add(t10);
          p.add(b2);
          p.add(b3);
          p.add(b4);
        }
      } catch (Exception e) {
      }

    } else if (s1.equals("Update")) {

      String y2 = t2.getText();
      String y3 = t3.getText();
      String update_id = t4.getText();
      String y4 = t5.getText();
      String y6 = t6.getText();
      String y7 = t7.getText();
      String y8 = t8.getText();
      String y9 = t9.getText();
      String y10 = t10.getText();
      try {
        String y = t1.getSelectedItem();
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:raman1");

        PreparedStatement ps =
            con.prepareStatement(
                "update mprofile  set Location=? , E_Mail_Id=? ,Contact_No =?, Address=?, D_O_B=?,Gender=?, Password=?, Manager_Id=?,manager_father=?,manager_name=? where  Manager_Id='"
                    + y
                    + "'  ");

        ps.setString(1, y10);
        ps.setString(2, y9);
        ps.setString(3, y8);
        ps.setString(4, y7);
        ps.setString(5, y6);
        ps.setString(6, g);
        ps.setString(7, y4);
        ps.setString(8, update_id);
        ps.setString(9, y3);
        ps.setString(10, y2);

        ps.executeUpdate();
        JOptionPane.showMessageDialog(p, "data has been updated");
        f.dispose();
        project p = new project();
        p.method();
      } catch (Exception e) {
        System.out.println(e);
      }
    } else if (s1.equals("Close")) {
      f.dispose();
    } else {
      f.dispose();
      project p = new project();
      p.method();
    }
  }