Mengisi Combo Box dengan data dari database [Ms.Acces]


berikut saya posting bagian dari program TA saya yang sudah saya share kemaren…

berikut screenshotnya..

public menu_login() {
initComponents();
tampilCombouser();

}
public void tampilCombouser(){
try {
String dbname="jdbc:odbc:counter";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(menu_login.class.getName()).log(Level.SEVERE, null, ex);
}
Connection con = DriverManager.getConnection(dbname,"admin","admin");
Statement statementcmbuser = (Statement) con.createStatement();
String sql = "SELECT * FROM login";
ResultSet resultSetcmbuser = statementcmbuser.executeQuery(sql);

while(resultSetcmbuser.next()){
cmbuser.addItem(resultSetcmbuser.getString("user"));
}

resultSetcmbuser.close();
statementcmbuser.close();

} catch (SQLException ex) {
System.out.println("Error :" + ex.toString());
}

}

Ket:
String dbname=”jdbc:odbc:counter”;

try {


Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);


} catch (ClassNotFoundException ex) {


Logger.getLogger(menu_login.class.getName()).log(Level.SEVERE, null, ex);


}


Connection con = DriverManager.getConnection(dbname,”admin”,”admin”);


Statement statementcmbuser = (Statement) con.createStatement();


String sql = “SELECT * FROM login”;

ResultSet resultSetcmbuser = statementcmbuser.executeQuery(sql);
merupakan pemanggilan database dengan nama database counter dan nama tabel login.
* cmbuser adalah nama variabel dari combo box.
* kita lihat di script Logger.getLogger(menu_login.class.getName()).log(Level.SEVERE, null, ex); seharusnya tidak ada script berikut, tapi dikarenakan kemaren pas waktu saya jalankan ada yang error jadi untuk menghilangkan error tsbt saya tambahkan script tsbt didalam fungsi try-catch.. fungsi script tsbt adalah untuk mendisable debug pada form program (menu_login).

semoga bermanfaat… :)

One thought on “Mengisi Combo Box dengan data dari database [Ms.Acces]

  1. hey there and thank you for your information –
    I’ve certainly picked up anything new from right here. I did however expertise several technical points using
    this website, as I experienced to reload the web site many times previous to I could get
    it to load properly. I had been wondering if your web host is OK?
    Not that I’m complaining, but slow loading instances times will very
    frequently affect your placement in google and could damage your quality score if
    advertising and marketing with Adwords. Anyway I am adding this
    RSS to my e-mail and could look out for a lot more of your respective intriguing content.
    Make sure you update this again very soon.

Berikan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s