Guest User

Untitled

a guest
Nov 25th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.Driver;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5.  
  6. public class Main
  7. {
  8. private static String URL =
  9. "jdbc:mysql://localhost:3306/mydb?autoReconnect=true&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC";
  10. private static String USERNAME = "Admin";
  11. private static String PASSWORD = "1260035";
  12.  
  13. public static void main(String[] args)
  14. {
  15. Connection connection = null;
  16. Driver driver;
  17.  
  18. try
  19. {
  20. driver = new com.mysql.cj.jdbc.Driver();
  21. DriverManager.registerDriver(driver);
  22. }
  23. catch(SQLException e)
  24. {
  25. System.err.println("Драйвер не зарегистрировался");
  26. }
  27.  
  28. try
  29. {
  30. connection = DriverManager.getConnection(URL,USERNAME,PASSWORD);
  31. if(!connection.isClosed())
  32. {
  33. System.out.println("Соединение установлено");
  34. }
  35. }
  36. catch(SQLException ex)
  37. {
  38. System.err.println("Соединение не установлено");
  39. }
  40. finally
  41. {
  42. if (connection != null) try {
  43. connection.close();
  44. } catch (SQLException e) {
  45. e.printStackTrace();
  46. }
  47. }
  48.  
  49. }
  50. }
Add Comment
Please, Sign In to add comment