Sie sind auf Seite 1von 7

this.

username = "";

Connector
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package qlnt;

this.password = ""; this.url = System.getProperty("user.dir")+ "\\database\\QuanLyDuoc.mdb"; }// end ConnectDB // ham khoi tao lop ConnectDB

public Connector(String username, String password, String url) { this.username = username; this.password = password;

import java.sql.*;

/** * * @author toanhb */ public class Connector {

this.url = url; }// end ConnectDB (String, String, String) // gan gia tri cho thuoc tinh username public Connector(String username, String password) { this.username = username; this.password = password; this.url = System.getProperty("user.dir")+ "\\database\\QuanLyDuoc.mdb"; }// end ConnectDB (String, String, String) // gan gia tri cho thuoc tinh username public void setUserName(String username) { this.username = username;

// danh sach cac bien cua lop ConnectDB public String username; public String password; "huynhbaotoan" // "root" //

public String url; // "jdbc:mysql://127.0.0.1:3306/mysql" private Connection conn; // ham khoi tao lop ConnectDB

public Connector() {

}// end setUserName(String) // gan gia tri cho thuoc tinh password

return this.url; }// end getUrl() // ham ket noi den co so du lieu co tham so truyen vao

public void setPassword(String password) { this.password = password; }// end setPassword(String) // gan gia tri cho thuoc tinh url

public boolean ConnectDB(String username, String password, String path) { try { Class.forName("sun.jdbc.odbc.J dbcOdbcDriver");

public void setURL(String url) { this.url = url; }// end setUrl(String) // lay gia tri cho thuoc tinh username

String url1 = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + path +";DriverID=22"; conn = DriverManager.getConnection(url1, username, password); System.out.println("Ket noi thanh cong den co so du lieu!"); return true; } catch (Exception e) { System.err.println("Khong ket noi duoc den co so du lieu!"); System.err.println(e.toString()) ; } return false; }// end ConnectDatabase(String, String, String) // ham ket noi den co so du lieu

public String getUserName() { return this.username; }// end getUserName() // lay gia tri cho thuoc tinh password

public String getPassword() { return this.password; }// end getPassword() // lay gia tri cho thuoc tinh url

public String getURL() {

public boolean ConnectDB(String username, String password) { try { Class.forName("sun.jdbc.odbc.J dbcOdbcDriver"); String url1 = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + this.url +";DriverID=22"; conn = DriverManager.getConnection(url1, username, password); System.out.println("Ket noi thanh cong den co so du lieu!"); return true; } catch (Exception e) { System.err.println("Khong ket noi duoc den co so du lieu!"); System.err.println(e.toString()) ; } return false; }// end ConnectDatabase(String, String, String) // ham ket noi den co so du lieu

System.out.println("Dong ket noi den co so du lieu!"); } catch (Exception e) { System.err.println(e.toString ()); } } }// end CloseDB() // thuc thi cau lenh SELECT

public ResultSet selectSQL(String strSQL) throws SQLException { Statement s = conn.createStatement(); ResultSet r = s.executeQuery(strSQL); return (r == null) ? null : r; }// end selectSQL(String) // thuc thi cau lenh UPDATE

public int updateSQL(String strSQL) throws SQLException { Statement s = conn.createStatement(); return (s.executeUpdate(strSQL));

public void CloseDB() { if (conn != null) { try { conn.close();

}// end updateSQL(String) // thuc thi cau lenh INSERT

public void insertSQL(String strSQL) throws SQLException { Statement s = conn.createStatement(); s.addBatch(strSQL); s.executeBatch(); }// end insertSQL(String) // thuc thi cau lenh DELETE

import java.sql.*;

/** * * @author toanhb */ public class Connector {

public void deleteSQL(String strSQL) throws SQLException { Statement s = conn.createStatement(); s.addBatch(strSQL); s.executeBatch(); }// end deleteSQL(String)

// danh sach cac bien cua lop ConnectDB public String username; public String password; "huynhbaotoan" // "root" //

public String url; // "jdbc:mysql://127.0.0.1:3306/mysql" private Connection conn; // ham khoi tao lop ConnectDB

}// end ConnectDB public Connector() { Quan ly ban hang this.username = ""; this.password = ""; this.url = System.getProperty("user.dir")+ "\\data\\QLBH.mdb"; }// end ConnectDB // ham khoi tao lop ConnectDB

Connector
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package qlbh;

public Connector(String username, String password, String url) {

this.username = username; this.password = password; this.url = url; }// end ConnectDB (String, String, String) // gan gia tri cho thuoc tinh username public Connector(String username, String password) { this.username = username; this.password = password; this.url = System.getProperty("user.dir")+ "\\database\\QuanLyDuoc.mdb"; }// end ConnectDB (String, String, String) // gan gia tri cho thuoc tinh username public void setUserName(String username) { this.username = username; }// end setUserName(String) // gan gia tri cho thuoc tinh password public String getURL() { return this.url; }// end getUrl() // ham ket noi den co so du lieu co tham so truyen vao public void setURL(String url) { this.url = url; }// end setUrl(String) // lay gia tri cho thuoc tinh username

public String getUserName() { return this.username; }// end getUserName() // lay gia tri cho thuoc tinh password

public String getPassword() { return this.password; }// end getPassword() // lay gia tri cho thuoc tinh url

public void setPassword(String password) { this.password = password; }// end setPassword(String) // gan gia tri cho thuoc tinh url

public boolean ConnectDB(String username, String password, String path) { try {

Class.forName("sun.jdbc.odbc.J dbcOdbcDriver"); String url1 = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + path +";DriverID=22"; conn = DriverManager.getConnection(url1, username, password); System.out.println("Ket noi thanh cong den co so du lieu!"); return true; } catch (Exception e) { System.err.println("Khong ket noi duoc den co so du lieu!"); System.err.println(e.toString()) ; } return false; }// end ConnectDatabase(String, String, String) // ham ket noi den co so du lieu

conn = DriverManager.getConnection(url1, username, password); System.out.println("Ket noi thanh cong den co so du lieu!"); return true; } catch (Exception e) { System.err.println("Khong ket noi duoc den co so du lieu!"); System.err.println(e.toString()) ; } return false; }// end ConnectDatabase(String, String, String) // ham ket noi den co so du lieu

public void CloseDB() { if (conn != null) { try { conn.close();

public boolean ConnectDB(String username, String password) { try { Class.forName("sun.jdbc.odbc.J dbcOdbcDriver"); String url1 = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + this.url +";DriverID=22";

System.out.println("Dong ket noi den co so du lieu!"); } catch (Exception e) { System.err.println(e.toString ()); } } }// end CloseDB()

// thuc thi cau lenh SELECT public void deleteSQL(String strSQL) throws SQLException { Statement s = conn.createStatement(); s.addBatch(strSQL); s.executeBatch(); }// end deleteSQL(String)

public ResultSet selectSQL(String strSQL) throws SQLException { Statement s = conn.createStatement(); ResultSet r = s.executeQuery(strSQL); return (r == null) ? null : r; }// end selectSQL(String) // thuc thi cau lenh UPDATE

}// end ConnectDB

public int updateSQL(String strSQL) throws SQLException { Statement s = conn.createStatement(); return (s.executeUpdate(strSQL)); }// end updateSQL(String) // thuc thi cau lenh INSERT

public void insertSQL(String strSQL) throws SQLException { Statement s = conn.createStatement(); s.addBatch(strSQL); s.executeBatch(); }// end insertSQL(String) // thuc thi cau lenh DELETE

Das könnte Ihnen auch gefallen