Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. package mysqlConnection;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class LoadDriver {
  8. private static String url = "jdbc:mysql://localhost:3306/patternframework";
  9. private static String driverName = "com.mysql.jdbc.Driver";
  10. private static String username = "root";
  11. private static String password = "rootme";
  12. private static Connection con;
  13.  
  14. public static Connection getConnection() {
  15. try {
  16. Class.forName(driverName);
  17. try {
  18. con = DriverManager.getConnection(url, username, password);
  19. } catch (SQLException ex) {
  20. // log an exception. fro example:
  21. System.out.println("Failed to create the database connection.");
  22. }
  23. } catch (ClassNotFoundException ex) {
  24. // log an exception. for example:
  25. System.out.println("Driver not found.");
  26. }
  27. return con;
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement