Advertisement
Afzzal87

Untitled

Jul 6th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package parQr;
  7. import java.sql.*;
  8.  
  9. /**
  10.  *
  11.  * @author EZHAKOVA1687
  12.  */
  13. public class koneksi {
  14.     public Connection conn;
  15.     public Statement st;
  16.     public ResultSet rs;
  17.    
  18.     public void koneksi()
  19.     {  
  20.         konek("localhost","db_parkir","root",""); */nama Database anda
  21.     }
  22.    
  23.     public void konek(String server, String db, String user,String passwd){
  24.         System.out.println("Keterangan");
  25.         try {
  26.             Class.forName("com.mysql.jdbc.Driver");
  27.         } catch (ClassNotFoundException e) {
  28.             System.out.println("Driver JDBC tidak barhasil Load");
  29.             e.printStackTrace();
  30.             return;
  31.         }
  32.         System.out.println("Driver berhasil di Load");
  33.         conn = null;
  34.         try {
  35.             conn = DriverManager.getConnection(
  36.             "jdbc:mysql://"+server+":3306/"+db,user,passwd);
  37.         } catch (SQLException e) {
  38.             System.out.println("Tidak bisa koneksi ke database");
  39.             e.printStackTrace();
  40.             return;
  41.         }
  42.         if (conn != null)
  43.             System.out.println("Berhasil Koneksi!");
  44.         else
  45.             System.out.println("Koneksi Gagal........ !");
  46.         }
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement