Advertisement
stevennathaniel

Kelas Koneksi di Java SE

Feb 9th, 2015
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 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 formPilihan;
  7.  
  8. import java.sql.Connection;
  9.  
  10. import java.sql.DriverManager;
  11.  
  12. import java.sql.SQLException;
  13.  
  14. import java.util.Properties;
  15.  
  16.  
  17.  
  18.  
  19.  
  20. /**
  21.  *
  22.  * @author steven
  23.  */
  24. public class kelasKoneksi {
  25.    
  26.     void Sambungan(){
  27.        
  28.        
  29.         try {
  30.            
  31.            
  32.             Connection Koneksi = null;
  33.            
  34.             String url = "jdbc:postgresql://localhost:5432/pdam";
  35.            
  36.             String user = "steven";
  37.            
  38.             String password = "kucing";
  39.            
  40.             Koneksi = DriverManager.getConnection(url,user,password);
  41.            
  42.             if(Koneksi != null);
  43.            
  44.             System.out.println("Berhasil Terkoneksi Ke Database");
  45.            
  46.            
  47.             Koneksi.close();
  48.            
  49.         }catch(SQLException ex){
  50.            
  51.            
  52.             ex.printStackTrace();
  53.         }
  54.        
  55.        
  56.     }
  57.    
  58.    
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement