Miletone

Rp0 / Rp1.000.000

Showing posts with label [JAVA] Connection Database MySQL. Show all posts
Showing posts with label [JAVA] Connection Database MySQL. Show all posts

Wednesday, November 25, 2020

[JAVA] Connection Database MySQL

 import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.swing.JOptionPane;


/**

 *

 * @author USER

 */

public class Koneksi {

    private static Connection koneksi;


public static Connection getKoneksi() {

if (koneksi == null) {

try {

String url = "jdbc:mysql://localhost/laundry";

String username = "root";

String password = "";


DriverManager.registerDriver(new com.mysql.jdbc.Driver());

koneksi = DriverManager.getConnection(url, username, password);

} catch (Exception ex) {

                    JOptionPane.showMessageDialog(null, "KONEKSI KE SERVER GAGAL !\n PERIKSALAH KEMBALI KONEKSI JARINGAN!");

                

}

}

return koneksi;

}

}