Guest User

Untitled

a guest
Jul 8th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. public class Main {
  2.  
  3. private static final String driverName = "com.mysql.jdbc.Driver";
  4. private static final String URL = "jdbc:mysql://localhost:3306/mydbtest?useSSL=false";
  5. private static final String USERNAME = "root";
  6. private static final String PASSWORD = "root";
  7.  
  8. public static void main(String[] args) {
  9.  
  10. try {
  11. Class.forName(driverName);
  12. } catch (ClassNotFoundException e) {
  13. System.out.println("Can't get class. No driver found");
  14. return;
  15. }
  16. Connection connection = null;
  17. try {
  18. connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
  19. } catch (SQLException e) {
  20. System.out.println("Can't get connection. Incorrect URL");
  21. return;
  22. }
  23. try {
  24. connection.close();
  25. } catch (SQLException e) {
  26. System.out.println("Can't close connection");
  27. return;
  28. }
  29. }
Add Comment
Please, Sign In to add comment