Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3.  
  4. public class DBManager {
  5.  
  6. private static final String DRIVER_NAME = "com.mysql.jdbc.Driver";
  7. private static final String DB_URL = "jdbc:mysql://localhost:3306/student";
  8. private static final String USERNAME = "root";
  9. private static final String PASSWORD = "123456";
  10.  
  11. public Connection getConnection() {
  12. Connection connection = null;
  13. try {
  14.  
  15. Class.forName(DRIVER_NAME);
  16. connection = DriverManager.getConnection(DB_URL,USERNAME,
  17. PASSWORD);
  18. System.out.println("Connected to database");
  19. } catch (Exception e) {
  20. e.printStackTrace();
  21. }
  22. return connection;
  23.  
  24. }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement