Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
32 views

Source Code Tabel Java

This document contains code to populate a JTable with data from a MySQL database table. It defines methods to connect to the database, retrieve data from a "tabel_data" table, and add each row returned to the JTable. The koneksi method establishes the database connection. The tabel method defines the table model, queries the data, and loads each result row into the JTable.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Source Code Tabel Java

This document contains code to populate a JTable with data from a MySQL database table. It defines methods to connect to the database, retrieve data from a "tabel_data" table, and add each row returned to the JTable. The koneksi method establishes the database connection. The tabel method defines the table model, queries the data, and loads each result row into the JTable.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

tabel

private void tabel(){


DefaultTableModel tb= new DefaultTableModel();
// Memberi nama pada setiap kolom tabel
tb.addColumn("Nip");
tb.addColumn("Nama");
tb.addColumn("Golongan");
tb.addColumn("Instansi");
tb.addColumn("Jabatan");
tb.addColumn("TMT CPNS");
tb.addColumn("Status");
tabelData.setModel(tb);
try{
// Mengambil data dari database
res=stat.executeQuery("select * from tabel_data");

while (res.next())
{
// Mengambil data dari database berdasarkan nama kolom pada tabel
// Lalu di tampilkan ke dalam JTable
tb.addRow(new Object[]{
res.getString("nip"),
res.getString("nama"),
res.getString("golongan"),
res.getString("instansi"),
res.getString("jabatan"),
res.getString("tmt_cpns"),
res.getString("status")
});
}

}catch (Exception e){


}
}

private Connection con;


private Statement stat;
private ResultSet res;

koneksi();
tabel();

koneksi

private void koneksi(){


try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/bkppd", "root",
"");
stat=con.createStatement();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}

You might also like