Advertisement
Guest User

Untitled

a guest
Aug 7th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. package Controle;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class Conecta_Banco {
  8.     Connection con = null;
  9.     String caminho = "jdbc:postgresql://localhost:5432/";
  10.     String usuario = "postgres";
  11.     String senha   = "123";
  12.    
  13.     public Connection conectaPostgre(String banco) throws SQLException{
  14.         try{
  15.             Class.forName("org.postgresql.Driver");
  16.             try{
  17.                 con = DriverManager.getConnection(caminho+banco,usuario,senha);
  18.             }catch(SQLException ex){
  19.                 System.out.println("Caminho, senha ou usuário incorreto!");
  20.             }
  21.         } catch(ClassNotFoundException ex){
  22.             System.out.println("Driver não encontrado");
  23.         }
  24.        
  25.         return con;
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement