Langsung aja bro..
package TB;
import java.sql.*;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
public class formDatabase extends javax.swing.JFrame {
public Connection conn;
public Statement st;
public ResultSet rs;
/** Creates new form formDatabase */
public formDatabase() {
initComponents();
koneksi();
tampilkandata();
setLocationRelativeTo(this);
}
public void koneksi(){
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokokelontong","root","");
st = conn.createStatement();
}catch (Exception e){
JOptionPane.showMessageDialog(null,"koneksi gagal..");
System.out.println(e.getMessage());
}
if (conn != null)
System.out.println("Berhasil Koneksi");
else
System.out.println("Gagal Koneksi");
}
public void tampilkandata() {
DefaultTableModel tabeltrans = new DefaultTableModel();
tabeltrans.addColumn("Nomor Transaksi");
tabeltrans.addColumn("Petugas");
tabeltrans.addColumn("Tanggal");
tabeltrans.addColumn("Kode Barang");
tabeltrans.addColumn("Nama Barang");
tabeltrans.addColumn("Harga");
tabeltrans.addColumn("Qty");
tabeltrans.addColumn("Total");
tabeltrans.addColumn("Subtotal");
tabeltrans.addColumn("Bayar");
tabeltrans.addColumn("Kembali");
try {
koneksi();
String sql = "select * from transaksi";
Statement stat = conn.createStatement();
ResultSet res=stat.executeQuery(sql);
while (res.next()) {
tabeltrans.addRow(new Object[]{res.getString(1),res.getString(2),res.getString(3),res.getString(4),
res.getString(5),res.getString(6),res.getString(7),res.getString(8),res.getString(9),
res.getString(10),res.getString(11)});
}
jTable1.setModel(tabeltrans);
} catch (Exception e) {
}
}
private void btnTutupActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new Transaksi().setVisible(true);
this.dispose();
}
Hasil :
package TB;
import java.sql.*;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
public class formDatabase extends javax.swing.JFrame {
public Connection conn;
public Statement st;
public ResultSet rs;
/** Creates new form formDatabase */
public formDatabase() {
initComponents();
koneksi();
tampilkandata();
setLocationRelativeTo(this);
}
public void koneksi(){
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tokokelontong","root","");
st = conn.createStatement();
}catch (Exception e){
JOptionPane.showMessageDialog(null,"koneksi gagal..");
System.out.println(e.getMessage());
}
if (conn != null)
System.out.println("Berhasil Koneksi");
else
System.out.println("Gagal Koneksi");
}
public void tampilkandata() {
DefaultTableModel tabeltrans = new DefaultTableModel();
tabeltrans.addColumn("Nomor Transaksi");
tabeltrans.addColumn("Petugas");
tabeltrans.addColumn("Tanggal");
tabeltrans.addColumn("Kode Barang");
tabeltrans.addColumn("Nama Barang");
tabeltrans.addColumn("Harga");
tabeltrans.addColumn("Qty");
tabeltrans.addColumn("Total");
tabeltrans.addColumn("Subtotal");
tabeltrans.addColumn("Bayar");
tabeltrans.addColumn("Kembali");
try {
koneksi();
String sql = "select * from transaksi";
Statement stat = conn.createStatement();
ResultSet res=stat.executeQuery(sql);
while (res.next()) {
tabeltrans.addRow(new Object[]{res.getString(1),res.getString(2),res.getString(3),res.getString(4),
res.getString(5),res.getString(6),res.getString(7),res.getString(8),res.getString(9),
res.getString(10),res.getString(11)});
}
jTable1.setModel(tabeltrans);
} catch (Exception e) {
}
}
private void btnTutupActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new Transaksi().setVisible(true);
this.dispose();
}
Hasil :
1. Silahkan masukkan komentar
2. Berkomentar dengan kata-kata yang santun
3. Jangan menggunakan kata-kata kotor
4. Jika anda tidak suka dengan yang kami sajikan, lebih baik jangan di baca
5. Tinggalkan link web/blog anda agar admin bisa visit back
6. Jadilah pengunjung yang baik
7. Kami hanya memberikan informasi dari sumber-sumber yang bisa admin percaya.
8. Maaf jika ada salah satu artikel tidak ada sumbernya.
EmoticonEmoticon