Advertisement
garapa

Conexão Banco de Dados

May 15th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. //Classe para conexão com banco de dados postgresql
  2.  
  3. package Project;
  4.  
  5. import java.sql.*;
  6. import java.util.logging.Level;
  7. import java.util.logging.Logger;
  8. import javax.swing.JOptionPane;
  9.  
  10. public class ConexaoBD {
  11.  
  12.     public Statement stm;
  13.     public ResultSet rs;
  14.     private String driver = "org.postgresql.Driver";
  15.     private String caminho = "jdbc:postgresql://localhost:5432/Garapa";
  16.     private String usuario = "postgres";
  17.     private String senha = "garapa";
  18.     public Connection con;
  19.  
  20.     public void Conexao(){
  21.      
  22.         try {
  23.         System.setProperty("jdbc.Drivers", driver);
  24.         con=DriverManager.getConnection(caminho, usuario, senha);
  25.         JOptionPane.showMessageDialog(null, "Conexão bem sucedida!");
  26. }
  27.  
  28.         catch (SQLException ex) {
  29.         JOptionPane.showMessageDialog(null, "Não foi possível se conectar ao banco de dados: "+ex);
  30. }
  31.  
  32.     }    
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement