public ArrayList<File> getFiles(String sql) {
   ArrayList<File> list = new ArrayList<File>();
   Connection conn = null;
   ResultSet rs = null;
   PreparedStatement ps = null;
   try {
     conn = getConnection();
     ps =
         conn.prepareStatement(
             sql.toLowerCase().startsWith("select")
                 ? sql
                 : ("SELECT FILENAME, MODIFIED FROM FILES WHERE " + sql));
     rs = ps.executeQuery();
     while (rs.next()) {
       String filename = rs.getString("FILENAME");
       long modified = rs.getTimestamp("MODIFIED").getTime();
       File file = new File(filename);
       if (file.exists() && file.lastModified() == modified) {
         list.add(file);
       }
     }
   } catch (SQLException se) {
     LOGGER.error(null, se);
     return null;
   } finally {
     close(rs);
     close(ps);
     close(conn);
   }
   return list;
 }
Beispiel #2
0
  public ValoresAtualizaJob retornaNovosValores(Connection conn, JobLote job) throws SQLException {

    PreparedStatement stmt = null;
    ResultSet rs = null;
    ValoresAtualizaJob obj = null;

    String sql =
        " select sum(qtd_transf) qtd_transf, sum(qtd_sucata) qtd_sucata, sum(hr_tot) hr_tot from joblote\n"
            + " where job = ? and operacao = ? ";

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

    if (rs.next()) {

      obj = new ValoresAtualizaJob();
      obj.setQtdTransf(rs.getDouble("qtd_transf"));
      obj.setQtdSucata(rs.getDouble("qtd_sucata"));
      obj.setHoraTotal(rs.getDouble("hr_tot"));
    }

    return obj;
  }
 public void excluir(Oriundo oriundo) throws SQLException {
   Connection con =
       DriverManager.getConnection(
           new conexao().url,
           new conexao().config.getString("usuario"),
           new conexao().config.getString("senha"));
   PreparedStatement ps = null;
   String sqlExcluir = "DELETE FROM oriundo WHERE codigo=?";
   try {
     ps = con.prepareStatement(sqlExcluir);
     ps.setInt(1, oriundo.getCodigo());
     ps.executeUpdate();
     JOptionPane.showMessageDialog(
         null, "Ecluido Com Sucesso: ", "Mensagem do Sistema - Excluir", 1);
   } catch (NumberFormatException e) {
     JOptionPane.showMessageDialog(
         null, "NumberFormaterExeption Erro: " + e.getMessage(), "ClasseDAO Func.Excluir", 0);
     e.printStackTrace();
   } catch (NullPointerException e) {
     JOptionPane.showMessageDialog(
         null, "NullPointerException Erro: " + e.getMessage(), "ClasseDAO Func. Excluir", 0);
     e.printStackTrace();
   } catch (SQLException e) {
     JOptionPane.showMessageDialog(
         null, "SQLException Erro: " + e.getMessage(), "ClasseDAO Func. Excluir", 0);
     e.printStackTrace();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         null, "Exception Erro: " + e.getMessage(), "ClasseDAO Func. Excluir", 0);
     e.printStackTrace();
   } finally {
     ps.close();
     con.close();
   }
 }
  public void actionPerformed(ActionEvent ae) {
    if (ae.getSource() == b1) {
      try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection con =
            DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "123");
        PreparedStatement ps =
            con.prepareStatement("select * from LoginForm where username=? and password=?");
        String UserName = t1.getText();
        String Password = jp1.getText();
        ps.setString(1, UserName);
        ps.setString(2, Password);
        ResultSet rs = ps.executeQuery();
        boolean flag = rs.next();
        if (flag) {
          new Main();
          f.setVisible(false);
        } else {
          JOptionPane.showMessageDialog(null, "Please Enter valid Name And Password");
        }

      } catch (Exception e) {
        System.out.println("Error:" + e);
      }
    } else if (ae.getSource() == b2) {
      t1.setText("");
      jp1.setText("");
    } else if (ae.getSource() == b3) {

      f.setVisible(false);
    }
  }
Beispiel #5
0
  public static int retornaQtdTotal(Connection conn, JobProtheus job) throws SQLException {

    PreparedStatement stmt = null;
    ResultSet rs = null;
    int qtdTotal = 0;
    int qtdSucata = 0;

    String sqlVerQtd =
        "select job, sum(qtd_transf), sum(hr_tot), sum(qtd_sucata) from jobLote where job = ? and operacao = ? group by job";
    stmt = conn.prepareStatement(sqlVerQtd);
    stmt.setString(1, job.getJob().trim());
    stmt.setInt(2, job.getOperacao());
    rs = stmt.executeQuery();

    String qtdJob = "";
    double totHora = 0;

    while (rs.next()) {
      qtdJob = rs.getString(1); // numero job
      qtdTotal = rs.getInt(2); // quantidade total
      totHora = rs.getInt(3); // hora total em minutos
      qtdSucata = rs.getInt(4);
    }

    return qtdTotal + qtdSucata;
  }
Beispiel #6
0
  private void LoginButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_LoginButtonActionPerformed
    // TODO add your handling code here:
    String sql = "select * from bruker where brukerNavn=? and brukerPassord=?";

    try {
      int userType = accountType.getSelectedIndex();

      pst = conn.prepareStatement(sql);
      pst.setString(1, UsrInput.getText());
      pst.setString(2, PswdInput.getText());
      rs = pst.executeQuery();

      if (rs.next()) {
        // JOptionPane.showMessageDialog(null,"Username and password is correct");
        close();
        if (userType == 0) {
          MainPage m = new MainPage();
          m.setVisible(true);
        } else {
          fMainPage fm = new fMainPage();
          fm.setVisible(true);
        }

      } else {
        JOptionPane.showMessageDialog(null, "Username or password is incorrect");
      }
    } catch (Exception e) {
      JOptionPane.showMessageDialog(null, e);
    }
  } // GEN-LAST:event_LoginButtonActionPerformed
Beispiel #7
0
  public JobIniciado retornaUltimoLote(Connection conn, String job, int operacao)
      throws SQLException {

    String sql =
        " select job, operacao, tripulacao,recurso, max(data_fim) \n"
            + "from joblote where job = ? and operacao = ? \n"
            + "group by job, operacao, tripulacao, recurso ";

    PreparedStatement stmt = null;
    ResultSet rs = null;
    JobIniciado iniciado = null;

    stmt = conn.prepareStatement(sql);
    stmt.setString(1, job.trim().replace(".", ""));
    stmt.setInt(2, operacao);
    rs = stmt.executeQuery();

    if (rs.next()) {

      iniciado = new JobIniciado();
      iniciado.setJob(rs.getString(1));
      iniciado.setOperacao(rs.getInt(2));
      iniciado.setTripulacao(rs.getDouble(3));
      iniciado.setRecurso(rs.getString(4));
      Timestamp data = rs.getTimestamp(5);
      iniciado.setData(Validacoes.getDataHoraString(data));
    }

    return iniciado;
  }
 public ArrayList<String> getStrings(String sql) {
   ArrayList<String> list = new ArrayList<String>();
   Connection conn = null;
   ResultSet rs = null;
   PreparedStatement ps = null;
   try {
     conn = getConnection();
     ps = conn.prepareStatement(sql);
     rs = ps.executeQuery();
     while (rs.next()) {
       String str = rs.getString(1);
       if (isBlank(str)) {
         if (!list.contains(NONAME)) {
           list.add(NONAME);
         }
       } else if (!list.contains(str)) {
         list.add(str);
       }
     }
   } catch (SQLException se) {
     LOGGER.error(null, se);
     return null;
   } finally {
     close(rs);
     close(ps);
     close(conn);
   }
   return list;
 }
Beispiel #9
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);
    }
  }
  private void fullAssociated() {

    boolean associated = true;

    String SQL =
        "Select * "
            + "from XX_VMR_REFERENCEMATRIX "
            + "where M_product IS NULL AND XX_VMR_PO_LINEREFPROV_ID="
            + LineRefProv.get_ID();

    try {
      PreparedStatement pstmt = DB.prepareStatement(SQL, null);
      ResultSet rs = pstmt.executeQuery();

      while (rs.next()) {
        associated = false;
      }

      rs.close();
      pstmt.close();

    } catch (Exception a) {
      log.log(Level.SEVERE, SQL, a);
    }

    if (associated == true) {
      String SQL10 =
          "UPDATE XX_VMR_PO_LineRefProv "
              + " SET XX_ReferenceIsAssociated='Y'"
              + " WHERE XX_VMR_PO_LineRefProv_ID="
              + LineRefProv.getXX_VMR_PO_LineRefProv_ID();

      DB.executeUpdate(null, SQL10);

      //			LineRefProv.setXX_ReferenceIsAssociated(true);
      //			LineRefProv.save();

      int dialog = Env.getCtx().getContextAsInt("#Dialog_Associate_Aux");

      if (dialog == 1) {
        ADialog.info(m_WindowNo, m_frame, "MustRefresh");
        Env.getCtx().remove("#Dialog_Associate_Aux");
      }

    } else {
      String SQL10 =
          "UPDATE XX_VMR_PO_LineRefProv "
              + " SET XX_ReferenceIsAssociated='N'"
              + " WHERE XX_VMR_PO_LineRefProv_ID="
              + LineRefProv.getXX_VMR_PO_LineRefProv_ID();

      DB.executeUpdate(null, SQL10);
      //			LineRefProv.setXX_ReferenceIsAssociated(false);
      //			LineRefProv.save();
    }
  }
Beispiel #11
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();
  }
  public static ResultSet collectRows1(String s) throws Exception {

    try {

      pps1.setString(1, s);
      rs = pps1.executeQuery();
    } catch (Exception e13) {
      System.out.println("" + e13);
    }
    return rs;
  }
  private void Update_table() {
    try {
      String sql = "SELECT * FROM trans where userid=?   order by date asc ";
      pst = conn.prepareStatement(sql);
      pst.setString(1, branch.getText());

      rs = pst.executeQuery();
      jTable1.setModel(DbUtils.resultSetToTableModel(rs));
    } catch (Exception e) {
      JOptionPane.showMessageDialog(null, e);
    }
  }
Beispiel #14
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();
  }
  public void cleanup() {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      conn = getConnection();
      ps = conn.prepareStatement("SELECT COUNT(*) FROM FILES");
      rs = ps.executeQuery();
      dbCount = 0;

      if (rs.next()) {
        dbCount = rs.getInt(1);
      }

      rs.close();
      ps.close();
      PMS.get().getFrame().setStatusLine(Messages.getString("DLNAMediaDatabase.2") + " 0%");
      int i = 0;
      int oldpercent = 0;

      if (dbCount > 0) {
        ps =
            conn.prepareStatement(
                "SELECT FILENAME, MODIFIED, ID FROM FILES",
                ResultSet.TYPE_FORWARD_ONLY,
                ResultSet.CONCUR_UPDATABLE);
        rs = ps.executeQuery();
        while (rs.next()) {
          String filename = rs.getString("FILENAME");
          long modified = rs.getTimestamp("MODIFIED").getTime();
          File file = new File(filename);
          if (!file.exists() || file.lastModified() != modified) {
            rs.deleteRow();
          }
          i++;
          int newpercent = i * 100 / dbCount;
          if (newpercent > oldpercent) {
            PMS.get()
                .getFrame()
                .setStatusLine(Messages.getString("DLNAMediaDatabase.2") + newpercent + "%");
            oldpercent = newpercent;
          }
        }
      }
    } catch (SQLException se) {
      LOGGER.error(null, se);
    } finally {
      close(rs);
      close(ps);
      close(conn);
    }
  }
Beispiel #16
0
 private void Update_table() {
   try {
     Connection conn = getConnect();
     String sql = "SELECT * FROM LoggedInPeople";
     PreparedStatement pst = conn.prepareStatement(sql);
     ResultSet rs = pst.executeQuery();
     PeopleLoggedIn.setModel(DbUtils.resultSetToTableModel(rs));
     closeConnect();
   } catch (Exception e) {
     System.out.println(e);
   }
 }
Beispiel #17
0
  public JobProtheus retornaJob(Connection conn, JobLote lote) throws SQLException {

    ResultSet rs = null;
    PreparedStatement stmt = null;
    JobProtheus job = null;

    String sql = "select job , B1_DESC,  operacao , produto,  ";
    sql += " dt_release, job_start_date , qtd_release, setor, qtd_transf ";
    sql += " from job left join  " + DB_PROTHEUS.trim() + ".dbo.SB1000 SB1 ";
    sql += " on(produto collate SQL_Latin1_General_CP1_CI_AS = B1_COD) ";
    sql += " where job = ? and operacao = ? and SB1.D_E_L_E_T_ = '' ";
    sql += " order by dt_release, produto ";

    stmt = conn.prepareStatement(sql);
    stmt.setString(1, lote.getJob().trim());
    stmt.setInt(2, lote.getOperNum());
    rs = stmt.executeQuery();

    while (rs.next()) {

      String nJob = rs.getString("job");
      int operacao = rs.getInt("operacao");
      String produto = rs.getString("produto");
      Date dataEmissao = rs.getDate("dt_release");
      Date dataPrevisaoInicio = rs.getDate("job_start_date");
      String descricaoProduto = rs.getString("B1_DESC");
      double quantidade = rs.getDouble("qtd_release");
      String wc = rs.getString("setor");

      String emissao = dataEmissao != null ? getDateToString(dataEmissao) : "";
      String previsaoInicio = dataPrevisaoInicio != null ? getDateToString(dataPrevisaoInicio) : "";

      job = new JobProtheus();

      job.setStatus("");
      job.setJob(nJob);
      job.setOperacao(operacao);
      job.setProduto(produto.trim());
      job.setDataEmissao(emissao);
      job.setQuantidadeLiberada(quantidade);
      job.setDescricaoProduto(descricaoProduto);
      job.setCentroTrabalho(wc);

      double qtdTotal = retornaQtdTotal(conn, job); // calcula o total transferido para o job
      job.setQuantidadeCompleta(qtdTotal);
      job.setDataPrivisaoInicio(previsaoInicio);
      job.setQuantidadeFaltando(quantidade - qtdTotal); // seta o valor qtd faltando
    }

    return job; // retorna lista de jobs
  }
  private void Update_Table() {
    try {

      String sql = "select * from Bank_001";
      PreparedStatement pst = conn.prepareStatement(sql);
      ResultSet rs = pst.executeQuery();

      table.setModel(DbUtils.resultSetToTableModel(rs));
      conn.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 public List<Oriundo> listar() throws SQLException {
   List<Oriundo> resultado = new ArrayList<Oriundo>();
   conexao propCon = new conexao();
   Connection con =
       DriverManager.getConnection(
           new conexao().url,
           propCon.config.getString("usuario"),
           propCon.config.getString("senha"));
   PreparedStatement ps = null;
   ResultSet rs = null;
   String sqlListar = "SELECT * FROM oriundo Order by codigo DESC";
   Oriundo oriundo;
   try {
     ps = con.prepareStatement(sqlListar);
     rs = ps.executeQuery();
     // if(rs==null){
     // return null;
     // }
     while (rs.next()) {
       oriundo = new Oriundo();
       oriundo.setCodigo(rs.getInt("codigo"));
       oriundo.setDescricao(rs.getString("descricao"));
       oriundo.setData_cadastro(rs.getDate("data_cadastro"));
       oriundo.setDia_fechamento(rs.getInt("dia_fechamento"));
       oriundo.setDia_pag(rs.getInt("dia_pag"));
       resultado.add(oriundo);
     }
   } catch (NumberFormatException e) {
     JOptionPane.showMessageDialog(
         null, "NumberFormaterExeption Erro: " + e.getMessage(), "ClasseDAO Func.Localizar", 0);
     e.printStackTrace();
   } catch (NullPointerException e) {
     JOptionPane.showMessageDialog(
         null, "NullPointerException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (SQLException e) {
     JOptionPane.showMessageDialog(
         null, "SQLException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         null, "Exception Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } finally {
     ps.close();
     con.close();
   }
   return resultado;
 }
Beispiel #20
0
  public boolean validLogin(String username, String password) {
    boolean validUser = false;
    try {

      dbStm =
          dbCon.prepareStatement(
              "SELECT * FROM userInfo WHERE username = "******"\"" + username + "\"" + ";");

      dbRs = dbStm.executeQuery();

      while (dbRs.next()) {
        String un = "";
        String pw = "";

        un = dbRs.getString("username");
        System.out.println(un + " " + username);
        pw = dbRs.getString("password");
        System.out.println(pw + " " + password);

        if (((username.equals(un) == true) && ((password.equals(pw) == true)))) {
          validUser = true;
          System.out.println("Valid User");
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
    }

    return validUser;
  }
  /**
   * metoda pobierajaca wszystkie rekordy z BD1.
   *
   * @return
   */
  public ArrayList<StudentFirst> getAllStudentFromDBfirst() {
    logger.info("getAllContactFromDB");
    ResultSet result = null;
    ArrayList<StudentFirst> students = new ArrayList<>();
    try {
      prepStmt = conn.prepareStatement("SELECT * FROM student1");
      result = prepStmt.executeQuery();
      int id, index;
      String name, surname, university, faculty, field;

      for (int i = 0; result.next(); i++) {
        id = result.getInt("stud1_id");
        index = result.getInt("stud1_index");
        name = result.getString("stud1_name");
        surname = result.getString("stud1_lastname");
        university = result.getString("stud1_university");
        faculty = result.getString("stud1_faculty");
        field = result.getString("stud1_field");
        students.add(new StudentFirst(id, index, name, surname, university, faculty, field));
        logger.info(students.get(i).toString());
      }

      if (students.size() == 0) {
        logger.info("Pusta BD?");
      }
      return students;
    } catch (SQLException e1) {
      JOptionPane.showMessageDialog(null, e1);
      e1.printStackTrace();
      return null;
    }
  }
Beispiel #22
0
  public boolean verificaSeSetorTemLinhaTempo(Connection conn, String setor) throws SQLException {

    PreparedStatement stmt = null;
    ResultSet rs = null;
    String sql = "select linha_tempo from setor where setor = ? and linha_tempo = ? ";

    stmt = conn.prepareStatement(sql);
    stmt.setString(1, setor.trim());
    stmt.setBoolean(2, true);
    rs = stmt.executeQuery();

    if (rs.next()) {
      return true;
    } else {
      return false;
    }
  }
 public Oriundo localizar(Integer codigo) throws SQLException {
   Connection con =
       DriverManager.getConnection(
           new conexao().url,
           new conexao().config.getString("usuario"),
           new conexao().config.getString("senha"));
   PreparedStatement ps = null;
   ResultSet rs = null;
   String sqlLocalizar = "SELECT * FROM oriundo WHERE codigo=?";
   Oriundo oriundo = new Oriundo();
   try {
     ps = con.prepareStatement(sqlLocalizar);
     ps.setInt(1, codigo);
     rs = ps.executeQuery();
     // if(!rs.next()){
     // return null;
     // }
     oriundo.setCodigo(rs.getInt("codigo"));
     oriundo.setDescricao(rs.getString("descricao"));
     oriundo.setData_cadastro(rs.getDate("data_cadastro"));
     oriundo.setDia_fechamento(rs.getInt("dia_fechamento"));
     oriundo.setDia_pag(rs.getInt("dia_pag"));
     return oriundo;
   } catch (NumberFormatException e) {
     JOptionPane.showMessageDialog(
         null, "NumberFormaterExeption Erro: " + e.getMessage(), "ClasseDAO Func.Localizar", 0);
     e.printStackTrace();
   } catch (NullPointerException e) {
     JOptionPane.showMessageDialog(
         null, "NullPointerException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (SQLException e) {
     JOptionPane.showMessageDialog(
         null, "SQLException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         null, "Exception Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } finally {
     ps.close();
     con.close();
   }
   return oriundo;
 }
Beispiel #24
0
  public boolean verificarSeJobEstaTabelaIniciado(Connection conn, String job, int operacao)
      throws SQLException {

    PreparedStatement stmt = null;
    ResultSet rs = null;
    String update = "select ativo from jobsiniciados where job = ? and operacao = ?";

    stmt = conn.prepareStatement(update);
    stmt.setString(1, job.trim().replace(".", ""));
    stmt.setInt(2, operacao);
    rs = stmt.executeQuery();

    if (rs.next()) {
      return true;
    }

    return false;
  }
  private void viewalllllActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_viewalllllActionPerformed
    try {

      String sql3 =
          "SELECT date,SUM(cost) AS TotalAmountReceived FROM trans WHERE branch=? GROUP BY date order by date asc";

      pst = conn.prepareStatement(sql3);
      pst.setString(1, branch.getText());

      rs = pst.executeQuery();

      jTable1.setModel(DbUtils.resultSetToTableModel(rs));

    } catch (Exception e) {
      JOptionPane.showMessageDialog(null, e);
    }
  } // GEN-LAST:event_viewalllllActionPerformed
  // 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);
    }
  }
Beispiel #27
0
 public void check_Password() {
   String password = "******";
   String sql = "Select * from user where user_id = '" + dataUser + "'";
   boolean password_valid = false;
   try {
     PreparedStatement stat = konek.prepareStatement(sql);
     ResultSet rset = stat.executeQuery();
     while (rset.next()) {
       password = rset.getString("psw");
       if (password.equalsIgnoreCase(dataPassword)) {
         password_valid = true;
         status_Proses(true, "Sukses!!!Password Valid...", 20);
       }
     }
     if (password_valid == false) {
       status_Proses(false, "Gagal!!!Password yang Anda Masukan Salah...", 20);
     }
   } catch (SQLException se) {
   }
 }
Beispiel #28
0
 public void check_User() {
   String user = "";
   String sql = "Select * from user";
   boolean user_valid = false;
   try {
     PreparedStatement stat = konek.prepareStatement(sql);
     ResultSet rset = stat.executeQuery();
     while (rset.next()) {
       user = rset.getString("username");
       if (user.equalsIgnoreCase(dataUser)) {
         user_valid = true;
         status_Proses(true, "Sukses!!!User Name Valid...", 20);
       }
     }
     if (user_valid == false) {
       status_Proses(false, "Gagal!!!User yang Anda Masukan Salah...", 20);
     }
   } catch (SQLException se) {
   }
 }
  private void viewallamountActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_viewallamountActionPerformed
    Object item = date1.getText();
    Object item1 = date2.getText();
    String sql =
        "select date,SUM(cost)  AS TotalAmountReceived from trans where branch=? and date between '"
            + item
            + "' and '"
            + item1
            + "'GROUP BY date order by date";
    try {
      pst = conn.prepareStatement(sql);
      pst.setString(1, branch.getText());

      rs = pst.executeQuery();

      jTable1.setModel(DbUtils.resultSetToTableModel(rs));
    } catch (Exception e) {
      JOptionPane.showMessageDialog(null, e);
    }
  } // GEN-LAST:event_viewallamountActionPerformed
Beispiel #30
0
  private void fill_combo() {
    try {
      String sql = "select distinct townname from towntrends.trends ";
      pst = conn.prepareStatement(sql);
      rs = pst.executeQuery();

      while (rs.next()) {
        String name = rs.getString("townname");
        jComboBox1.addItem(name);
      }
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(null, ex);
    } finally {
      try {
        pst.close();
        rs.close();
      } catch (Exception ex) {

      }
    }
  }