Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ultil;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class ConnectDB {
- private Connection conn;
- private String url;
- private String username;
- private String password;
- public ConnectDB(){
- this.url = "jdbc:mysql://localhost:3306/tintuc?useUnicode=true&characterEncoding=UTF-8";
- this.password = "";
- this.username = "root";
- }
- public Connection getConnection(){
- //nạp driver
- try {
- Class.forName("com.mysql.jdbc.Driver");
- //tạo chuỗi kết nối
- conn = DriverManager.getConnection(url, username, password);
- } catch (ClassNotFoundException | SQLException e) {
- e.printStackTrace();
- }
- return conn;
- }
- }
Add Comment
Please, Sign In to add comment