Advertisement
Guest User

Untitled

a guest
Jun 1st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. package br.unisul.exemplo.core.dao.connection;
  2.  
  3.  
  4.  
  5. import java.sql.Connection;
  6.  
  7. import java.sql.DriverManager;
  8.  
  9. import java.sql.SQLException;
  10.  
  11.  
  12.  
  13. public class ConexaoJDBC {
  14.  
  15.  
  16.  
  17.     public static final String driver = "org.postgresql.Driver";
  18.  
  19.     public static final String url =
  20.  
  21.         "jdbc:postgresql://localhost:5432/postgres";
  22.  
  23.     public static final String usuario = "postgres";
  24.  
  25.     public static final String senha = "unisul";
  26.  
  27.  
  28.  
  29.     //importar de java.sql.
  30.  
  31.     public static Connection getConnection() {
  32.  
  33.         Connection con = null;
  34.  
  35.         try {
  36.  
  37.             Class.forName(driver);
  38.  
  39.             con = DriverManager.getConnection(url, usuario, senha);
  40.  
  41.         } catch (SQLException e) {
  42.  
  43.             e.printStackTrace();
  44.  
  45.         } catch (ClassNotFoundException e) {
  46.  
  47.             e.printStackTrace();
  48.  
  49.         }
  50.  
  51.    
  52.  
  53.     return con;
  54.  
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement