Advertisement
Guest User

Untitled

a guest
May 6th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class ConnectionTest
  4. {
  5.  
  6. public static void main(String[] args)
  7. {
  8. Connection conn = null;
  9.  
  10. try
  11. {
  12. String userName = "openmrs";
  13. String password = "openmrs";
  14. String url = "jdbc:mysql://127.0.0.1:3306/openmrs";
  15. Class.forName ("com.mysql.jdbc.Driver").newInstance ();
  16. conn = DriverManager.getConnection (url, userName, password);
  17. System.out.println ("Database connection established");
  18. }
  19. catch (Exception e)
  20. {
  21. System.err.println ("Cannot connect to database server");
  22. e.printStackTrace();
  23. }
  24. finally
  25. {
  26. if (conn != null)
  27. {
  28. try
  29. {
  30. conn.close ();
  31. System.out.println ("Database connection terminated");
  32. }
  33. catch (Exception e) { /* ignore close errors */ }
  34. }
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement