Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Kết nối tới CSDL
- public Connection connect() {
- Connection con = null;
- String url = "jdbc:mysql://localhost:3306/phanxuong";
- try {
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection(url, "root", "123456");
- } catch (Exception e) {
- e.printStackTrace();
- }
- return con;
- }
- //select
- public ResultSet select(String sql, Connection connect) {
- ResultSet rs = null;
- try {
- rs = connect.createStatement().executeQuery(sql);
- }catch (SQLException e) {
- e.printStackTrace();
- }
- return rs;
- }
- //Update
- public int update(String sql, Connection connect) {
- int rs = 0;
- try {
- rs = connect.createStatement().executeUpdate(sql);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return rs;
- }
- //Dong ket noi CSDL
- public void closeConnection(Connection connect) {
- try {
- connect.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement