Advertisement
Guest User

Untitled

a guest
Oct 6th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. public class ConnectionFactory {
  2.  
  3. private static final String DRIVER = "org.postgressql.Driver";
  4. private static final String URL = "jdbc:postgresql://localhost:5432/NomedoDB";
  5. private static final String USER = "postgres";
  6. private static final String PASS = "";
  7.  
  8. public static Connection getConnection() throws SQLException {
  9. try {
  10. Class.forName(DRIVER);
  11.  
  12. return DriverManager.getConnection(URL, USER, PASS);
  13. } catch (ClassNotFoundException ex) {
  14. throw new RuntimeException("Erro na conexão", ex);
  15. }
  16. }
  17. }
  18.  
  19. public static void main(String[] args) throws SQLException {
  20. // TODO code application logic here
  21. ConnectionFactory conn = new ConnectionFactory();
  22. conn.getConnection();
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement