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 TAMPIL



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 frame1 extends javax.swing.JFrame {

    /** Creates new form frame1 */
    public frame1() {
        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/dbsi7", "root", "");

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

    }

    public void tampilkandata() {
        DefaultTableModel tabelmhs = new DefaultTableModel();
        tabelmhs.addColumn("NIM");
        tabelmhs.addColumn("NAMA");    
        try {
            koneksi();            
            String sql = "select * from mhs";
            Statement stat = conn.createStatement();
            ResultSet res=stat.executeQuery(sql);
            while (res.next()) {
                tabelmhs.addRow(new Object[]{res.getString(1),res.getString(2)});
            }
           jTable1.setModel(tabelmhs);                  
        } 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