Advertisement
pendekar_langit

koneksi

Mar 3rd, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 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 engine;
  7.  
  8. import com.mysql.jdbc.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.PreparedStatement;
  11. import java.sql.SQLException;
  12. import java.util.logging.Level;
  13. import java.util.logging.Logger;
  14. import javax.swing.JOptionPane;
  15.  
  16. /**
  17.  *
  18.  * @author root
  19.  */
  20. public class koneksi {
  21.     private Connection conn;
  22.     private ConfigDB config = new ConfigDB();
  23.         /**
  24.      * Function for message box information
  25.      */
  26.    
  27.     private static void infoBox(String infoMessage){
  28.         JOptionPane.showMessageDialog(null, infoMessage, "Informasi", JOptionPane.INFORMATION_MESSAGE);
  29.     }
  30.    
  31.      /**
  32.      * Function for message box warning
  33.      */
  34.    
  35.     private static void warningBox(String infoMessage){
  36.         JOptionPane.showMessageDialog(null, infoMessage, "Peringatan", JOptionPane.WARNING_MESSAGE);
  37.     }
  38.    
  39.      /**
  40.      * Function for message box information
  41.      */
  42.    
  43.     private static void errorBox(String infoMessage){
  44.         JOptionPane.showMessageDialog(null, infoMessage, "Kesalahan", JOptionPane.ERROR_MESSAGE);
  45.     }
  46.     public Connection getcon(){
  47.         try {
  48.             Class.forName("com.mysql.jdbc.Driver");//1. Load Driver
  49.             String db = "jdbc:mysql://"+config.getServer()+":"+config.getPort()+"/"+config.getDB();//2. Memanggil alamat database
  50.             String userdb = config.getUsername();//username default database
  51.             String passdb = config.getPassword();//password default database
  52.             conn = (Connection) DriverManager.getConnection(db,userdb,passdb);//3. Membuat Koneksi Database
  53.         } catch (Exception e) {
  54.             errorBox("Silakan cek koneksi database.");
  55.         }
  56.         return conn;
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement