Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. package Database;
  2.  
  3. import java.sql.DriverManager;
  4.  
  5. public class Connection {
  6.  
  7. public java.sql.Connection connection;
  8.  
  9. public java.sql.Connection getConnection() {
  10.  
  11. String userName = "root";
  12. String password = "";
  13.  
  14. try {
  15. Class.forName("com.mysql.jdbc.Driver");
  16. System.out.println("Connecting to Database....");
  17. connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/stockmanagement?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT", "root","");
  18.  
  19. } catch (Exception ex) {
  20. System.out.println(ex.toString());
  21. System.out.println("Couldn't Connect to the database.\nEither the database isn't online or it doesn't exist.");
  22. System.exit(1);
  23. }
  24.  
  25. return connection;
  26.  
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement