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 void setContent(String cat) { cat = cat.trim(); selectAllCB.setVisible(false); selectAllCB.setSelected(false); deleteBut.setVisible(false); restoreBut.setVisible(false); refreshBut.setVisible(true); Object columns[] = null; int count = 0; switch (cat) { case "Inbox": columns = new Object[] {"", "From", "Date", "Subject", "Content"}; count = Database.getCount("Inbox"); workingSet = db.getData("SELECT * FROM messages WHERE tag='inbox' ORDER BY msg_id desc"); ; break; case "SentMail": columns = new Object[] {"", "To", "Date", "Subject", "Content"}; count = Database.getCount("Sentmail"); workingSet = db.getData("SELECT * FROM messages WHERE tag='sentmail' ORDER BY msg_id desc"); break; case "Draft": columns = new Object[] {"", "To", "Date", "Subject", "Content"}; count = Database.getCount("Draft"); workingSet = db.getData("SELECT * FROM messages WHERE tag='draft' ORDER BY msg_id desc"); break; case "Outbox": columns = new Object[] {"", "To", "Date", "Subject", "Content"}; count = Database.getCount("Outbox"); workingSet = db.getData("SELECT * FROM messages WHERE tag='outbox' ORDER BY msg_id desc"); break; case "Trash": // restoreBut.setVisible(true); columns = new Object[] {"", "To/From", "Date", "Subject", "Content"}; count = Database.getCount("Trash"); workingSet = db.getData( "SELECT * FROM messages,trash WHERE messages.tag='trash' and messages.msg_id=trash.msg_id ORDER BY deleted_at desc"); break; default: System.out.println("in default case"); } if (count > 0) { selectAllCB.setVisible(true); rows = new Object[count][]; msgID = new int[count]; try { workingSet.beforeFirst(); for (int i = 0; i < count && workingSet.next(); i++) { msgID[i] = workingSet.getInt(1); rows[i] = new Object[] { false, workingSet.getString(2), workingSet.getDate(3), workingSet.getString(4), workingSet.getString(5) }; } } catch (SQLException sqlExc) { JOptionPane.showMessageDialog(null, sqlExc, "EXCEPTION", JOptionPane.ERROR_MESSAGE); sqlExc.printStackTrace(); } tableModel = new MyDefaultTableModel(rows, columns); table = new JTable(tableModel); table.getSelectionModel().addListSelectionListener(this); table.addMouseListener(this); table.getTableHeader().setOpaque(true); table.getTableHeader().setReorderingAllowed(false); // table.getTableHeader().setBackground(Color.blue); table.getTableHeader().setForeground(Color.blue); // table.setRowSelectionAllowed(false); // table.setColumnSelectionAllowed(false); table.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 14)); table.setRowHeight(20); table.setFillsViewportHeight(true); TableColumn column = null; for (int i = 0; i < 5; i++) { column = table.getColumnModel().getColumn(i); if (i == 0) { column.setPreferredWidth(6); } else if (i == 3) { column.setPreferredWidth(250); } else if (i == 4) { column.setPreferredWidth(450); } else { column.setPreferredWidth(40); } } table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); remove(contentPan); contentPan = new JScrollPane(table); contentPan.setBackground(Color.orange); contentPan.setOpaque(true); contentPan.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); add(contentPan, "Center"); Home.home.homeFrame.setVisible(true); } else { JPanel centPan = new JPanel(new GridBagLayout()); centPan.setBackground(new Color(52, 86, 70)); JLabel label = new JLabel("No Messages In This Category"); label.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 22)); label.setForeground(Color.orange); centPan.add(label); remove(contentPan); contentPan = new JScrollPane(centPan); contentPan.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); add(contentPan, "Center"); contentPan.repaint(); } }
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); } }