-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathconnection_mysql.java
More file actions
43 lines (36 loc) · 1.25 KB
/
connection_mysql.java
File metadata and controls
43 lines (36 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* 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.
Require Depedencies mysql-connector
*/
package com.mycompany.siekeusekolah;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.SQLException;
import javax.swing.JOptionPane;
/**
*
* @author rico
*/
public class Koneksi {
public Connection konekDB;
public Statement perintah;
public Koneksi() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost/javadb";
String user = "root";
String pass = "ricoyoga12";
konekDB = DriverManager.getConnection(url, user, pass);
perintah = konekDB.createStatement();
System.out.println("Berhasil Terhubung");
} catch (SQLException salahe) {
JOptionPane.showMessageDialog(null, "Gagal Terhubung Database");
System.err.print("Gagal koneksi: " + salahe.getMessage());
} catch (ClassNotFoundException salahe) {
System.err.print("Class Tidak Ditemukan: " + salahe.getMessage());
}
}
}