Advertisement
Guest User

Untitled

a guest
Jan 4th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. //Kết nối tới CSDL
  2.    
  3.     public Connection connect() {
  4.         Connection con = null;
  5.         String url = "jdbc:mysql://localhost:3306/phanxuong";
  6.         try {
  7.             Class.forName("com.mysql.jdbc.Driver");
  8.             con = DriverManager.getConnection(url, "root", "123456");
  9.             } catch (Exception e) {
  10.         e.printStackTrace();
  11.         }
  12.         return con;
  13.     }
  14.     //select
  15.     public ResultSet select(String sql, Connection connect) {
  16.         ResultSet rs = null;
  17.         try {
  18.             rs = connect.createStatement().executeQuery(sql);
  19.         }catch (SQLException e) {
  20.             e.printStackTrace();
  21.         }
  22.         return rs;
  23.     }
  24.     //Update
  25.     public int update(String sql, Connection connect) {
  26.     int rs = 0;
  27.     try {
  28.         rs = connect.createStatement().executeUpdate(sql);
  29.     } catch (SQLException e) {
  30.         e.printStackTrace();
  31.     }
  32.     return rs;
  33.     }
  34.     //Dong ket noi CSDL
  35.     public void closeConnection(Connection connect) {
  36.         try {
  37.         connect.close();
  38.         } catch (SQLException e) {
  39.             e.printStackTrace();
  40.         }
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement