Guest User

Untitled

a guest
Oct 19th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. package ultil;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class ConnectDB {
  8. private Connection conn;
  9. private String url;
  10. private String username;
  11. private String password;
  12.  
  13. public ConnectDB(){
  14. this.url = "jdbc:mysql://localhost:3306/tintuc?useUnicode=true&characterEncoding=UTF-8";
  15. this.password = "";
  16. this.username = "root";
  17. }
  18. public Connection getConnection(){
  19. //nạp driver
  20. try {
  21. Class.forName("com.mysql.jdbc.Driver");
  22. //tạo chuỗi kết nối
  23. conn = DriverManager.getConnection(url, username, password);
  24. } catch (ClassNotFoundException | SQLException e) {
  25. e.printStackTrace();
  26. }
  27. return conn;
  28. }
  29.  
  30. }
Add Comment
Please, Sign In to add comment