Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ContohLaporan;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import javax.swing.JOptionPane;
- public class DBConnection {
- private Connection conn = null;
- static String DB_URL, DB_USER, DB_PASS, dbname, host, port;
- boolean koneksi = false, db = false;
- public DBConnection() {
- host = "localhost";
- port = "3306";
- dbname = "db_supermarket_siti3";
- DB_USER = "root";
- DB_PASS = "";
- DB_URL = "jdbc:mysql://" + host + ":" + port + "/" + dbname;
- if (conn == null) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);
- koneksi = true;
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null,
- ex.getErrorCode() + ": " + ex.getMessage());
- koneksi = false;
- } catch (ClassNotFoundException cne) {
- JOptionPane.showMessageDialog(null,
- "COM.MYSQL.JDBC.Driver tidak ditemukan\n" + cne.getMessage());
- koneksi = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement