Advertisement
Guest User

Untitled

a guest
Nov 27th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. package jbdcdemo;
  2.  
  3. import java.sql.*;
  4.  
  5. public class Driver {
  6. private final static String DRIVER_NAME = "com.mysql.jdbc.Driver";
  7. private final static String URL = "jdbc:mysql://127.0.0.1:3306/";
  8. private final static String USERNAME = "root";
  9. private final static String PASSWORD = "150250911";
  10. private final static String DATABASE = "mco2";
  11.  
  12. public Connection getConnection() {
  13. try {
  14. Class.forName(DRIVER_NAME);
  15.  
  16. Connection myConn = DriverManager.getConnection(
  17. URL +
  18. DATABASE + "?autoReconnect=true&useSSL=false",
  19. USERNAME,
  20. PASSWORD);
  21. System.out.println("Connection Successful");
  22. return myConn;
  23. }
  24. catch (SQLException e) {
  25. System.out.println("SQL error, connection unsuccesful");
  26. e.printStackTrace();
  27. return null;
  28. }
  29. catch (ClassNotFoundException e) {
  30. System.out.println("Class not found, connection unsuccesful");
  31. e.printStackTrace();
  32. return null;
  33. }
  34. }
  35.  
  36. public static void main(String[] args) {
  37. System.out.println("Connecting...");
  38. Driver db = new Driver();
  39. db.getConnection();
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement