Advertisement
Guest User

Untitled

a guest
Jan 4th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 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/QLNV";
  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.     }
  42.     public void LoadDataCmbCty() throws SQLException
  43.     {
  44.         String s1 = cmbMaCT.getItemAt(cmbMaCT.getSelectedIndex());
  45.         Connection con = connect();
  46.         ResultSet rs = select("select MaCty from CONGTY", con);
  47.            
  48.         while(rs.next())
  49.         {
  50.             cmbMaCT.addItem(rs.getString("MaCty"));
  51.         }
  52.            
  53.     }
  54.     public int checkNumberString(String number) {
  55.         Pattern pattern = Pattern.compile("^[0-9]*$");
  56.         Matcher matcher = pattern.matcher(number);
  57.         if (!matcher.matches())
  58.             return 0;//"Chuỗi nhập vào không phải là số!";
  59.          else return 1;
  60.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement