Advertisement
Guest User

Untitled

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