Вы находитесь на странице: 1из 4

ActiveNET™ DAO write-up

Standalone program accessing database

Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver
”);
Connection
con=DriverManager.getConnection(“jdbc:odbc:
mysqlDSN”, “root”, “active”);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(“SELECT *
FROM emp”); Emp
empno, ename, desig, sal
while(rs.next()) 1
2
{ 3
System.out.println(rs.getInt(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
System.out.println(rs.getDouble(4));
}
rs.close();
stmt.close();
con. close();

www.activenetindia.com 1
ActiveNET™ DAO write-up

DAO sample
interface EmpDAO class Emp implements Serializable
{ {
Emp getEmployee(int empNo); private int emoNo;
Collection getEmployees(); private String ename, desig;
Collection getEmployeesByDesig(String private double sal;
desig); public Emp(){} Emp
Collection getEmployeesBySal(double public void setEmpNo(int eno) empno, ename, desig, sal
sal); {empNo=eno;} 1
void insertEmp(Emp emp); public int getEmpNo(){return empNo;} 2
3
void updateEmp(Emp emp); }
void deleteEmp(int empNo);

class EmpMySQLDAOImpl

class EmpEJBDAOImpl

class EmpLDAPDAOImpl

class EmpXLSDAOImpl

class EmpIIOPDAOImpl

Use a Data Access Object (DAO) to abstract and encapsulate all access to the data
source. The DAO manages the connection with the data source to obtain and store data.

The DAO implements the access mechanism required to work with the data source. The
data source could be a persistent store like an RDBMS, an external service like a B2B
exchange, a repository like an LDAP database, or a business service accessed via
CORBA Internet Inter-ORB Protocol (IIOP) or low-level sockets. The business
component that relies on the DAO uses the simpler interface exposed by the DAO for its
clients. The DAO completely hides the data source implementation details from its
clients. Because the interface exposed by the DAO to clients does not change when the
underlying data source implementation changes, this pattern allows the DAO to adapt to
different storage schemes without affecting its clients or business components.
Essentially, the DAO acts as an adapter between the component and the data source.

www.activenetindia.com 2
ActiveNET™ DAO write-up

Business object
is a Servlet/EJB/standalone/Applet program

DAO
which hides how to access different data sources to access the data
interface EmpDAO, class EmpMySQLDAOImpl, class EmpEJBDAOImpl

DataSource is from where we access database - DB/EJB/Speardsheet/LDAP/CORBA

www.activenetindia.com 3
ActiveNET™ DAO write-up

Transfer Object
POJO (Plain Old JavaBean Object) is called Transfer Object in which the data retrieved
from various datasources are stored and moved in different layers of the application
architecture
Emp
Transfer Object
(VO/POJO)
Servlet
create/use
create/use Emp
empno, ename, desig, sal
1
Standalone 2
3

Applet DAO Implementation


classes for
various data sources

JSP

EJB

CORBA

www.activenetindia.com 4

Вам также может понравиться