Advertisement
yoesuv

Konek_DB

Aug 13th, 2013
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. package login;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. import javax.swing.JOptionPane;
  8.  
  9. public class Konek_DB {
  10.    
  11.     private static Connection koneksi;
  12.     private static String url,user,pass;
  13.  
  14.     public static Connection getKoneksi(){
  15.         if(koneksi==null){
  16.             url = "jdbc:mysql://localhost/db_login";
  17.             user = "root";
  18.             pass = "root";
  19.            
  20.             try {
  21.                 DriverManager.registerDriver(new com.mysql.jdbc.Driver());
  22.                 koneksi = DriverManager.getConnection(url, user, pass);
  23.                 //JOptionPane.showMessageDialog(null, "Koneksi ke Database Berhasil");
  24.             } catch (SQLException e) {
  25.                 JOptionPane.showMessageDialog(null, e.getMessage());
  26.                 System.exit(0);
  27.                
  28.             }
  29.         }
  30.         return koneksi;
  31.        
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement