예제 #1
0
  public void setQuery(String q) {
    cache = new Vector();
    try {
      ResultSet rs = statement.executeQuery(q);
      ResultSetMetaData meta = rs.getMetaData();
      colCount = meta.getColumnCount();
      headers = new String[colCount];
      for (int h = 1; h <= colCount; h++) {
        headers[h - 1] = meta.getColumnName(h);
      }
      while (rs.next()) {
        String[] record = new String[colCount];
        for (int i = 0; i < colCount; i++) {
          record[i] = rs.getString(i + 1);
        }
        cache.addElement(record);
      } // while sonu

      fireTableChanged(null);
    } // try sonu
    catch (Exception e) {
      cache = new Vector();
      e.printStackTrace();
    }
  } // setQuery sonu
예제 #2
0
  private void Simpan() {

    if (btnSave.getText().equals("Edit")) {
      try {
        Class.forName(KoneksiDatabase.driver);
        java.sql.Connection c =
            DriverManager.getConnection(
                KoneksiDatabase.database, KoneksiDatabase.user, KoneksiDatabase.pass);
        Statement s = c.createStatement();

        String sql;
        sql = "update absensi_lembur set tipehari = '";
        sql += cmbJenisHari.getSelectedItem() + "', tot_waktu_lembur='";
        sql += txtTotalLembur.getText() + "'";
        sql += "where kd_absen = '" + txtKodeAbsen.getText() + "'";
        s.executeQuery(sql);

        JOptionPane.showMessageDialog(
            null, "Data Berhasil Disimpan!!!", "Informasi", JOptionPane.INFORMATION_MESSAGE);
      } catch (Exception e) {
        JOptionPane.showMessageDialog(
            null,
            "Gagal Disimpan, Data Harus Lengkap !!!",
            "Peringatan",
            JOptionPane.WARNING_MESSAGE);
      }
    }
    Baru();
  }
예제 #3
0
  private void Baru() {
    btnSave.setText("Save");
    txtNip.requestFocus();
    txtNip.setText("");

    try {
      Class.forName(KoneksiDatabase.driver);
      java.sql.Connection c =
          DriverManager.getConnection(
              KoneksiDatabase.database, KoneksiDatabase.user, KoneksiDatabase.pass);
      Statement s = c.createStatement();
      String sql = "select * from absensi_lembur";
      ResultSet rs = s.executeQuery(sql);

      final String[] headers = {
        "Kd Absen",
        "NIP",
        "Tgl Absen",
        "Masuk",
        "Pulang",
        "Hari",
        "Tipe Hari",
        "Terlambat",
        "Lembur",
        "Tipe Lembur",
        "Tot Lembur",
        "Tunj Makan",
        "Tunj Transport"
      };
      rs.last();

      int n = rs.getRow();
      Object[][] data = new Object[n][13];
      int p = 0;
      rs.beforeFirst();
      while (rs.next()) {
        data[p][0] = rs.getString(1);
        data[p][1] = rs.getString(2);
        data[p][2] = rs.getString(3);
        data[p][3] = rs.getString(4);
        data[p][4] = rs.getString(5);
        data[p][5] = rs.getString(6);
        data[p][6] = rs.getString(7);
        data[p][7] = rs.getString(8);
        data[p][8] = rs.getString(9);
        data[p][9] = rs.getString(10);
        data[p][10] = rs.getString(11);
        data[p][11] = rs.getString(12);
        data[p][12] = rs.getString(13);
        p++;
      }
      tblLembur.setModel(new DefaultTableModel(data, headers));
      tblLembur.setAlignmentX(CENTER_ALIGNMENT);

    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          null, "Gagal Koneksi, Ada Kesalahan.", "Warning", JOptionPane.WARNING_MESSAGE);
    }
  }
  public ItensVendidos() {
    super("Itens Vendidos");
    JButton imprimir;

    final DefaultTableModel modelo = new DefaultTableModel();

    // constrói a tabela
    JTable tabela = new JTable(modelo);

    // Cria duas colunas
    modelo.addColumn("Código");
    modelo.addColumn("Vendedor");
    modelo.addColumn("Produto");
    modelo.addColumn("Quantidade");

    imprimir = new JButton("Imprimir");
    imprimir.setBounds(100, 450, 30, 24);

    // exibe os dados da tabela MySQL
    // Conexao banco = new Conexao();
    String retorno = "erro";
    try {
      // Connection ExConn = (Connection) banco.abrirBDconn();
      Class.forName("com.mysql.jdbc.Driver");
      Connection conexao = DriverManager.getConnection("jdbc:mysql://localhost/banco", "root", "");
      Statement stmt = conexao.createStatement();

      // procedimentos para obter os dados de uma tabela

      String query = "SELECT * FROM venda2";
      ResultSet rs = stmt.executeQuery(query);

      while (rs.next()) {
        int id = rs.getInt("idVendedor");
        String nome = rs.getString("nomeVendedor");
        String produto = rs.getString("produto");
        int qtd = rs.getInt("qtd");
        modelo.addRow(new Object[] {new Integer(id), nome, produto, new Integer(qtd)});
      }

      // fim procedimento para obter os dados
    } catch (SQLException ex) {
      System.out.println("SQLException: " + ex.getMessage());
      System.out.println("SQLState: " + ex.getSQLState());
      System.out.println("VendorError: " + ex.getErrorCode());
    } catch (Exception e) {
      System.out.println("Problemas ao tentar conectar com o banco de dados");
    }
    // fim MySQL

    tabela.setPreferredScrollableViewportSize(new Dimension(350, 50));

    Container c = getContentPane();
    c.setLayout(new FlowLayout());

    JScrollPane scrollPane = new JScrollPane(tabela);
    c.add(scrollPane);
    c.add(imprimir);

    setSize(400, 300);
    setVisible(true);
  }
예제 #5
0
파일: RAJ5.java 프로젝트: alvarporcar/POW
  public RAJ5(String sAno) {
    int files;
    int cols;

    String query11 = "drop table if exists tempAJ5 ";
    String query22 = "drop table if exists tempAJ5a ";

    String query1 = "create table tempAJ5 ";
    query1 += "select ano,descripcion as oficina,materia,sum(num) as num ";
    query1 += "from asist_juridica,oficinas ";
    query1 += "where (ano=\"" + sAno + "\") and (asist_juridica.oficina=oficinas.codigo) ";
    query1 += "group by materia,oficina ";
    query1 += "order by materia";

    String query2 = "CREATE TABLE `tempAJ5a` ( ";
    query2 += "`ano` char(4) default '0', ";
    query2 += "`materia` char(15) default '0', ";
    query2 += "`of_benassal` int(3) unsigned default '0', ";
    query2 += "`of_montanejos` int(3) unsigned default '0', ";
    query2 += "`of_morella` int(3) unsigned default '0', ";
    query2 += "`of_onda` int(3) unsigned default '0', ";
    query2 += "`of_segorbe` int(3) unsigned default '0', ";
    query2 += "`of_traiguera` int(3) unsigned default '0'";
    query2 += ") ";

    String query3 = "Select * from tipo_asist_jur";

    String query4 = "select * from tempAJ5";

    try {
      Connection con = this.getConnection();

      Statement sentencia11 = con.createStatement();
      sentencia11.execute(query11);
      sentencia11.close();

      Statement sentencia22 = con.createStatement();
      sentencia22.execute(query22);
      sentencia22.close();

      Statement sentencia1 = con.createStatement();
      sentencia1.execute(query1);
      sentencia1.close();

      Statement sentencia2 = con.createStatement();
      sentencia2.execute(query2);
      sentencia2.close();

      Statement sentencia3 = con.createStatement();
      ResultSet rs3 = sentencia3.executeQuery(query3);

      Statement sentencia4 = con.createStatement();
      ResultSet rs4 = sentencia4.executeQuery(query4);

      String query5 = "";
      String materia = "";
      int quantitat, quantitat1, quantitat2, quantitat3, quantitat4, quantitat5, quantitat6;

      while (rs3.next()) {
        materia = rs3.getString("abreviatura");
        quantitat = 0;
        quantitat1 = 0;
        quantitat2 = 0;
        quantitat3 = 0;
        quantitat4 = 0;
        quantitat5 = 0;
        quantitat6 = 0;
        while (rs4.next()) {
          if (materia.equals(rs4.getString("materia"))) {
            quantitat = rs4.getInt("num");
            if (rs4.getString("oficina").equals("OF. BENASAL")) {
              quantitat1 = quantitat;
            } else if (rs4.getString("oficina").equals("OF. MONTANEJOS")) {
              quantitat2 = quantitat;
            } else if (rs4.getString("oficina").equals("OF. MORELLA")) {
              quantitat3 = quantitat;
            } else if (rs4.getString("oficina").equals("OF. ONDA")) {
              quantitat4 = quantitat;
            } else if (rs4.getString("oficina").equals("OF. SEGORBE")) {
              quantitat5 = quantitat;
            } else if (rs4.getString("oficina").equals("OF. TRAIGUERA")) {
              quantitat6 = quantitat;
            }
          }
        }
        query5 =
            "insert into tempAJ5a values (\""
                + sAno
                + "\",\""
                + materia
                + "\","
                + quantitat1
                + ","
                + quantitat2
                + ","
                + quantitat3
                + ","
                + quantitat4
                + ","
                + quantitat5
                + ","
                + quantitat6
                + ")";
        Statement sentencia5 = con.createStatement();
        sentencia5.execute(query5);
        sentencia5.close();
        rs4.beforeFirst();
      }
      sentencia3.close();
      sentencia4.close();

      // select final per a formar la matriu AbstractTableModel
      String query6 =
          "select *,sum(of_traiguera+of_benassal+of_morella+of_onda+of_segorbe+of_montanejos)as total ";
      query6 += "from tempAJ5a ";
      query6 += "group by materia";

      Statement sentencia6 = con.createStatement();
      ResultSet rs6 = sentencia6.executeQuery(query6);
      ResultSetMetaData rsmd6 = rs6.getMetaData();

      files = 0;
      while (rs6.next()) {
        files++;
      }
      cols = rsmd6.getColumnCount();

      f = new Object[files][cols];
      c = new Object[cols];

      for (int i = 0; i < cols; i++) {
        c[i] = rsmd6.getColumnName(i + 1);
      }

      int x = 0;
      rs6.beforeFirst();
      while (rs6.next()) {
        for (int y = 0; y < cols; y++) {
          if ((y >= 2) && (y <= 8)) {
            f[x][y] = new Integer(rs6.getString(y + 1));
          } else {
            f[x][y] = rs6.getString(y + 1);
          }
        }
        x++;
      }
      sentencia6.close();
      con.close();

    } catch (SQLException e) {
      System.err.println("Error en la base de dades: " + e);
    }
  }