Guest User

Untitled

a guest
Jun 11th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. //STEP 1. Import required packages
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import javax.swing.*;
  5. import java.sql.*;
  6.  
  7.  
  8. public class ConnectionPostgres {
  9. Connection c = null;
  10.  
  11.  
  12. public static Connection dbConnector() {
  13.  
  14. try {
  15. Class.forName("org.postgresql.Driver");
  16. Connection c = DriverManager
  17. .getConnection("jdbc:postgresql://127.0.0.1:5432/sensorthings",
  18. "sensorthings", "1");
  19. return c;
  20.  
  21. } catch (Exception e) {
  22. // e.printStackTrace();
  23. //System.err.println(e.getClass().getName()+": "+e.getMessage());
  24. //System.exit(0);
  25. JOptionPane.showMessageDialog(null, e);
  26. return null;
  27. }
  28. //System.out.println("Opened database successfully");
  29. }
  30. }
Add Comment
Please, Sign In to add comment