You are on page 1of 2

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import javax.swing.JOptionPane;

/**

* @author User

*/

public class Class_Koneksi {

private Connection connect;

private String driverName ="com.mysql.cj.jdbc.Driver";

private String url = "jdbc:mysql://localhost:3306/crud";

private String username = "root";

private String password= "";

public static void main(String[] args) throws SQLException {

Class_Koneksi koneksi = new Class_Koneksi ();

koneksi.getClass_Koneksi();

public Connection getClass_Koneksi()throws SQLException{


if (connect==null){

try{

Class.forName(driverName);

System.out.println("Class Driver Ditemukan");

try{

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

System.out.println("Koneksi Database Sukses");

catch(SQLException se){

System.out.println("Koneksi Database Gagal"+se);

System.exit(0);

catch(ClassNotFoundException cnfe){

System.out.println("Class Driver Tidak Ditemukan, terjadi kesalahan pada:"+cnfe);

return connect;

You might also like