Pages

Dokumentasi untuk memunculkan database di combobox

void initGol() {
        go.removeAllItems();

        Statement ste = null;
        ResultSet rse = null;

        try {
            konek k = new konek();
            conn = k.login();
            ste = conn.createStatement();
            String sql = "SELECT jenis from golongan order by jenis ASC";
            rse = ste.executeQuery(sql);
            while (rse.next()) {
                String no = rse.getString("jenis");
                go.addItem(no);
            }
            gol = go.getSelectedItem().toString();
        } catch (Exception e) {
            System.out.println(e);
        } finally {
            try {
                if (rse != null) {
                    rse.close();
                }
            } catch (SQLException e) {
            }
            try {
                if (ste != null) {
                    ste.close();
                }
            } catch (SQLException e) {
            }
        }
    }

Dokumentasi pencarian nama obat

private void cariobatKeyPressed(java.awt.event.KeyEvent evt) {                                    
        try {
            String nm = cariobat.getText();
            conn = (Connection) new konek().login();
            statement = conn.createStatement();
            MTObat.getDataVector().removeAllElements();
            String sql = "select idobat, jenis, namaobat,   keterangan from obat o, golongan g , satuanobat s WHERE o.idgolongan=g.idgolongan AND s.idsatuan=o.idsatuan AND namaobat like '%" + nm + "%'";
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()) {
                Object[] data = {rs.getString("idobat"),                    
                    rs.getString("jenis"),
                    rs.getString("namaobat"),
                    rs.getString("keterangan"),};
                MTObat.addRow(data);
            }


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


Dokumentasi insert date from date.util to mysql


 public String setDate(String date) {
        String tg = "";
        String tgl[] = date.split("-");

      
        if (tgl[1].equals("Jan")) {
            tg = tgl[0] + "-" + "01"+ "-" + tgl[2];
        } else if (tgl[1].equals("Feb")) {
           tg = tgl[0] + "-" + "02"+ "-" + tgl[2];
        } else if (tgl[1].equals("Mar")) {
            tg = tgl[0] + "-" + "03"+ "-" + tgl[2];
        }else if (tgl[1].equals("Apr")) {
            tg = tgl[0] + "-" + "04"+ "-" + tgl[2];
        }else if (tgl[1].equals("Mei")) {
            tg = tgl[0] + "-" + "05"+ "-" + tgl[2];
        }else if (tgl[1].equals("Jun")) {
            tg = tgl[0] + "-" + "06"+ "-" + tgl[2];
        }else if (tgl[1].equals("Jul")) {
            tg = tgl[0] + "-" + "07"+ "-" + tgl[2];
        }else if (tgl[1].equals("Agu")) {
            tg = tgl[0] + "-" + "08"+ "-" + tgl[2];
        }else if (tgl[1].equals("Sep")) {
            tg = tgl[0] + "-" + "09"+ "-" + tgl[2];
        }else if (tgl[1].equals("Okt")) {
            tg = tgl[0] + "-" + "10"+ "-" + tgl[2];
        }else if (tgl[1].equals("Nov")) {
            tg = tgl[0] + "-" + "11"+ "-" + tgl[2];
        }else{
        tg = tgl[0] + "-" + "12"+ "-" + tgl[2];
        }
        return tg;
    }

Dokumentasi pembobotan fungsi

untuk menyimpan jumlah[kolom]fungsi di database
public void simpenkolomfungsi() {
        konek k = new konek();
        conn = (Connection) k.login();
       // String a = null;
        //String b = null;

        try {
            statement = conn.createStatement();
            String sql = "SELECT idobat, COUNT( * ) AS jumlahfungsi FROM fungsiobat GROUP BY idobat ORDER BY idfungsiobat DESC LIMIT 1";
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()) {
                String a = rs.getString("idobat").toString();
                String b = rs.getString("jumlahfungsi").toString();

                System.out.println("idobat : " + a + " jumlah fungsi : " + b + " ");
                try {
                    statement = conn.createStatement();
                    String sqlok = "INSERT INTO temp_fungsi (idobat,totalfungsi) values('" + a + "','" + b + "')";
                    System.out.println("simpan idobat : " + a + " bobot : " + b + " ");
                    statement.executeUpdate(sqlok);
                } catch (Exception e) {
                    System.err.println("gagal : " + e);
                }
            }
        } catch (Exception e) {
            System.err.println("kacau : " + e);
        }

    }


untuk pembobotan fungsi
public String FuzzyFungsi(String n) {
        int jumlah = Integer.parseInt(n);
        String nilai = null;
        if ((jumlah <= 10) && (jumlah >= 8)) {
            nilai = "5";
        } else if ((jumlah < 8) && (jumlah >= 6)) {
            nilai = "4";
        } else if ((jumlah < 6) && (jumlah >= 4)) {
            nilai = "3";
        } else if ((jumlah < 4) && (jumlah >= 2)) {
            nilai = "2";
        } else {
            nilai = "1";
        }
        return nilai;
    }
 untuk simpan bobot fungsi ke dalam tabel bobot_fungsi
 public void simpenDatabobot() {
        konek k = new konek();
        conn = (Connection) k.login();
        String oo = null;
        String c = null;

        try {
            statement = conn.createStatement();
            String sql2 = "SELECT idobat, totalfungsi FROM  temp_fungsi  ORDER BY idtempfungsi DESC LIMIT 1";
            ResultSet rsa = statement.executeQuery(sql2);
            while (rsa.next()) {
                c = rsa.getString("idobat").toString();
                String d = rsa.getString("totalfungsi").toString();
                oo = FuzzyFungsi(d);
                System.out.println("idobat : " + c + " bobot : " + oo + " ");
                try {
                    statement = conn.createStatement();
                    String sql3 = "INSERT INTO bobot_fungsi (idobat,bobotfungsi) values('" + c + "','" + oo + "')";
                    System.out.println("simpan idobat : " + c + " bobot : " + oo + " ");
                    statement.executeUpdate(sql3);
                } catch (Exception e) {
                    System.err.println("gagal : " + e);
                }
            }
        } catch (Exception e) {
            System.err.println("kacau : " + e);
        }

    }


jangan lupa letakkan method simpenDatabobot(); di aksi JButton

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        saveData();
        simpenkolomfungsi();
        simpenDatabobot();
        int brs = TFungsi.getRowCount();
        for (int i = 0; i < brs; i++) {
            MTFungsi.removeRow(0);
        }

        awal();
        showTableDaftar();
        
    }