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/QLNV";
- 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();
- }
- }
- public void LoadDataCmbCty() throws SQLException
- {
- String s1 = cmbMaCT.getItemAt(cmbMaCT.getSelectedIndex());
- Connection con = connect();
- ResultSet rs = select("select MaCty from CONGTY", con);
- while(rs.next())
- {
- cmbMaCT.addItem(rs.getString("MaCty"));
- }
- }
- public int checkNumberString(String number) {
- Pattern pattern = Pattern.compile("^[0-9]*$");
- Matcher matcher = pattern.matcher(number);
- if (!matcher.matches())
- return 0;//"Chuỗi nhập vào không phải là số!";
- else return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement