Advertisement
Guest User

Untitled

a guest
Nov 16th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. /*
  2. compile: javac DatabaseConnectionDemo.java
  3. execute: java -cp .;lib\postgresql-X.X.XXXX.jar DatabaseConnectionDemo
  4. */
  5.  
  6. //package io.uetoyo.gists;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.SQLException;
  10. import java.sql.DriverManager;
  11.  
  12. class DatabaseConnectionDemo {
  13.  
  14. public static void main(String[] args) {
  15.  
  16. Connection connection = null;
  17. String url = "jdbc:postgresql://SERVER_NAME/DATABASE_NAME";
  18.  
  19. try {
  20. connection = DriverManager.getConnection(url, "USER", "PASSWORD");
  21. System.out.println("Success");
  22. } catch (SQLException ex) {
  23. System.out.println("Error");
  24. } finally {
  25. if (connection != null) {
  26. try {
  27. connection.close();
  28. } catch (SQLException ex) {
  29. // Handle or ignore the exception.
  30. }
  31. }
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement