logo bloglogo blog
Selamat Datang Di Blog Hanif
Terima kasih atas kunjungan Anda di blog Hanif ,
semoga apa yang saya share di sini bisa bermanfaat dan memberikan motivasi pada kita semua
untuk terus berkarya dan berbuat sesuatu yang bisa berguna untuk orang banyak.

CODING JAVA KONEK DATABASE





import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;

public class matapelajaran extends javax.swing.JFrame {

    /** Creates new form matapelajaran */
    public matapelajaran() {
        initComponents();
         tampilkandata();
    }
public Connection conn;

    public void koneksi() throws SQLException {
        try {
            conn=null;
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/akademik", "root", "");

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(matapelajaran.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException e) {
            Logger.getLogger(matapelajaran.class.getName()).log(Level.SEVERE, null, e);
        } catch (Exception es) {
            Logger.getLogger(matapelajaran.class.getName()).log(Level.SEVERE, null, es);
        }

    }

    public void tampilkandata() {
        DefaultTableModel tabelmapel = new DefaultTableModel();
        tabelmapel.addColumn("KODE MAPEL");
        tabelmapel.addColumn("NAMA MAPEL");
     
        try {
            koneksi();
            String sql = "select * from barang";
            Statement stat = conn.createStatement();
            ResultSet res=stat.executeQuery(sql);
            while (res.next()) {
                tabelmapel.addRow(new Object[]{res.getString(1),res.getString(2)});
            }
           jTable1.setModel(tabelmapel);
        } catch (Exception e) {
        }

    }

Enter your email address to get update from Hanif.
Print PDF
Next
« Prev Post
Previous
Next Post »

Copyright © 2013. HANIF NURMAN - Created by Hanif