Welcome

Thursday, 26 July 2018

Membuat Koneksi Database ke Netbeans

buat class java dengan nama koneksi.java
database mysql dengan Nama kepegawaian
add library mysql jdbc

masukan souce code dibawah ini :

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;

    public class koneksi {
        public static void main(String[] args){
         
        }
 
    private static Connection koneksi;
    public static Connection getKoneksi() {
        if (koneksi==null) {
            try {
                String Host="jdbc:mysql://localhost:3306/kepegawaian";
                String User="root";
                String Pass="";
                DriverManager.registerDriver(new com.mysql.jdbc.Driver());
                koneksi = DriverManager.getConnection(Host, User,Pass);
            } catch (SQLException e) {
                JOptionPane.showMessageDialog(null, "Gagal Koneksi"+e);
            }
        }
        return koneksi;
    }

No comments:

Post a Comment

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();
Designed By Yudho C Setyawan