untuk menyimpan jumlah[kolom]fungsi di database
untuk pembobotan fungsi
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
jangan lupa letakkan method simpenDatabobot(); di aksi JButton
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(); }
Tidak ada komentar:
Posting Komentar