SlideShare a Scribd company logo
1 of 44
Using JDBC in the Project (Project Architecture)
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
with DAO Design Pattern
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
with DAO Design Pattern
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
with DAO Design Pattern
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
with DAO Design Pattern
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
with DAO Design Pattern
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
with DAO Design Pattern
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
with DAO Design Pattern
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
with DAO Design Pattern
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
with DAO Design Pattern
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
with DAO Design Pattern
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
with DAO Design Pattern
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
with DAO Design Pattern
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
with DAO Design Pattern
http://rajjdbc.blogspot.in/
Using JDBC in the Project (Project Architecture)
with DAO Design Pattern
http://rajjdbc.blogspot.in/
What is Low Level Persistence Logic?
• Low Level means it is specific to one type of dependent persistence logic
• Persistence Logic: is responsible for accessing persistence Data
• If I’m using low level persistence logic in Business Logic (i.e High Level
Logic) so I can not connect to all the Back end servers.
• To avoid this problem we have to use another layer , keep the persistence
logic in a separate object, that object is nothing but a Data Access Object
(DAO).
•
• SO here DAO is a Design Pattern, Design Pattern which gives a solution for
a problem.
• (Example: I’m facing a problem, I will try to interact with a friend who is
already faced the problem because he will have ready made solution for
that problem, no need to waste my time to solve the problem, because
already ready made solution (design pattern) is available
http://rajjdbc.blogspot.in/
What is Low Level Persistence Logic?
http://rajjdbc.blogspot.in/
Introducing DAO
• When it comes into the project (enterprise
application) we need to concentrate in
optimizing the code, making the more
reusable, and also testable.
• The DAO is the most common pattern
implemented into the enterprise applications.
http://rajjdbc.blogspot.in/
What is a Pattern?
• Pattern is a three part document that describes
the context (situation), reoccurring problem and
the best solution for the problem in the given
context (situation).
• The software patterns are categorized into
multiple type for convenience in learning and
applying.
• The design patterns is one of the category. This
lists the patterns describing the problems related
to design and development of the software
applications
http://rajjdbc.blogspot.in/
THE DAO DESIGN PATTERN:
•
• As the title describes this is a design pattern
• Context (situation):
• We want to create enterprise Application with reasonable business logic having a requirement of accessing
multiple (variety) of datastore and /or found that may have a requirement of migrating from one type of data
store (database) to other. Easy to migrate between the different types of data stores. That is in my application I
want to connect to LDAP to take credentials, same application I want to connect to File Systems to accept login
details.
• Problem:
• We want to separate the low-level persistence (data access) logic from Business Logic. But this so this solution
leaves a problem that is how do you separate in a best way? Thus this solution we kept in a problem.
• Forces: (Why):
• We want to have a proper responsibility division that is:
• (a) improves the quality of the system.
• (b) reduces the cost and time for the development
• To enable unit testing, make the system more comfortable for testing.
• Easy to migrate between the different types of data stores.
• Solution:
• Implement the low-level persistence logic into a separate object, exposing the data access operations through
high-level API to the service layer.
http://rajjdbc.blogspot.in/
What is DAO ?
• Ans: DAO is a design pattern that describes
separating the low-level persistence logic from
the business logic, implementing into a
separate (independent) object.
•
• Note: this special object introduced
implementing the DAO pattern is also refered
as a DAO i.e: Data Access Object
http://rajjdbc.blogspot.in/
http://rajjdbc.blogspot.in/
• From this discussion and the above
architecture we understand JDBC is used for
implementing the DAO in Java for accessing
the tabular data store
http://rajjdbc.blogspot.in/
Use Case diagram of our project
http://rajjdbc.blogspot.in/
Implementing DAO Design Pattern in
our project
http://rajjdbc.blogspot.in/
Implementing the Data Access Layer for ‘CreateEmployee’ use
case of ‘Employee Management System (EMS).
• For Example:
• Implementing the Data Access Layer for ‘CreateEmployee’ use case of ‘Employee Management System (EMS).
•
• //EmployeeDAOI.java
• package com.st.ems.dao;
• public interface EmployeeDAOI
• {
• void save(int eno,String name, double sal, int dno);
• //we will change this struture later
• //we will add some more methods as we proceed
• }
•
•
• //EmployeeDAO.java
• package com.st.ems.dao.jdbc;
• import com.st.ems.dao.EmployeeDAOI;
• import java.sql.*;
• import java.util.*;
• public class EmployeeDAO implements EmployeeDAOI
• {
• public void save(int eno, String name,double sal, int dno)
• {
• //this method is responsible for saving the given details into emp table
• //to do: execute the following SQL
• String sql="insert into emp values("+eno+",'"+name+",',"+sal+","+dno+")";
http://rajjdbc.blogspot.in/
• //how to execute?
• //use JDBC
• //Write this Connection con=null here only to make visible to all the blocks
• Connection con=null;//null is necessary whn u r declaring as a local variable
• try
• {
• //step 1.1
• String driverClassName="oracle.jdbc.driver.OracleDriver";//here we are using oracle driver
• Class c=Class.forName(driverClassName);
• Driver d=(Driver)c.newInstance();
• //step 1.2
• String jdbcUrl="jdbc:oracle:thin:@localhost:1521:XE";
• Properties p=new Properties();
• p.put("user","system");
• p.put("password","manager");
• //Connection con=null;//i can not use con ref variable in finally block as it is local to this
• block
•
•
http://rajjdbc.blogspot.in/
• con=d.connect(jdbcUrl,p);
• //step2
• Statement st=con.createStatement();
• //step3
• st.executeUpdate(sql);
•
•
• }//end of try block
• catch(Exception e)
• {
• e.printStackTrace();
• //to report the error, we will set run time error
• throw new RuntimeException(e);
• }
• finally
• {
• try
• {
• //step 4:
• con.close();
•
• }//try
• catch(Exception e){}
• }//finally
•
•
• }//save
• }//class
http://rajjdbc.blogspot.in/
• /* now we are writing Tese case for DAO object [that is save()] for this we have to use JUNIT but
• we are using main() for this application
• */
• //EmployeeDAOTestCase.java
• import com.st.ems.dao.jdbc.EmployeeDAO;
• import com.st.ems.dao.EmployeeDAOI;
•
•
• public class EmployeeDAOTestCase
• {
• private EmployeeDAOI edao;
• public void testsave()
• {
• edao.save(102,"e102",20000,20);
• System.out.println("Details saved");
• }
• public static void main(String s[])
• {
• EmployeeDAOTestCase test=new EmployeeDAOTestCase();
• test.edao=new EmployeeDAO();
• test.testsave();//here Driver object is created
• //test.testsave();//here 2nd Driver object is created but one Driver object is enought to handle
• //multiple request from diffrent clients, connections as it is a Thread -safe
• }
• }
http://rajjdbc.blogspot.in/
• /*
• D:materialjava(E DRIVE)javaAdvJavajdbcDAO>javac
-d . *.java
• D:materialjava(E
DRIVE)javaAdvJavajdbcDAO>D:materialjava(E
• DRIVE)javaAdvJavajdbcDAO>set
classpath=C:oraclexeappor
• acleproduct10.2.0serverjdbclibojdbc14.jar;.;
• D:materialjava(E DRIVE)javaAdvJavajdbcDAO>java
EmployeeDAOTestCase
• Details saved
• */
http://rajjdbc.blogspot.in/
Work flow of our program
http://rajjdbc.blogspot.in/
Q: is our DAO created efficient?
• Ans: No, we need to multiple changes. Let us look into all of them
one after the other
• In the EmployeeDAO created earlier the save() method is
programmed to create a new instance (object) of Driver class on
every request, which is not effective.
• Considering the following points with respect to the Driver:
• The Driver object is Thread-safe means Driver object performs
consistently even on concurrent requests from multiple threads
• A single instance of Driver can be used to create multiple
connections because it is Thread-safe. If we create the multiple
instances of Driver class, unnecessarly garbage is stored into the
memory, and performance becomes slow.
• Considering these points a single instance of Driver is enough for an
application per data base.
http://rajjdbc.blogspot.in/
http://rajjdbc.blogspot.in/
• (INTRODUCTION TO DRIVER MANAGER)
• That means we want to redesign the DAO such that it should work with single instance of Driver class irrespective
of the number of clients and requests.
• To address this requirements JDBC introduces DriverManager class
• Q: What is Driver Manager class?
• The java.sql.DriverManager is a factory class that is designed to create the Connection Managing the Driver
objects.
• Why DriverManager?
• Ans: to centralize the code( means connect() method) creating the Connection using the Driver object. So that we
can avoid multiple instances (objects) of a Driver class to create. Here the code means connect() method.
•
• Q: How DriverManager functions?
• We know that the basic functionality of the DriverManager is to create the Connection managing the Driver
object. The getConnection() method will create connection using registered Driver object.
•
• Working with DriverManager
• Fig: DriverManager FactoryClass(.JPG
• The following two steps are involved in doing this:
• Step1: Register the Driver to DriverManager
• Step2: Invoke the getConnection() to get the Connection
•
http://rajjdbc.blogspot.in/

More Related Content

What's hot

Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer ReferenceMuthuselvam RS
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Pooja Talreja
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)suraj pandey
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivitybackdoor
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types pptkamal kotecha
 
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...Pallepati Vasavi
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database ConnectivityRanjan Kumar
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)Maher Abdo
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate pptAneega
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servletsNuha Noor
 

What's hot (20)

JDBC
JDBCJDBC
JDBC
 
Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer Reference
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
 
Jdbc complete
Jdbc completeJdbc complete
Jdbc complete
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
Chap3 3 12
Chap3 3 12Chap3 3 12
Chap3 3 12
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
 
Overview Of JDBC
Overview Of JDBCOverview Of JDBC
Overview Of JDBC
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
 
Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
 
JSP - Part 1
JSP - Part 1JSP - Part 1
JSP - Part 1
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
 
Hibernate
HibernateHibernate
Hibernate
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
 

Similar to Dao example

Utilized Code Gen To Save Our Efforts In Sap Integration
Utilized Code Gen To Save Our Efforts In Sap IntegrationUtilized Code Gen To Save Our Efforts In Sap Integration
Utilized Code Gen To Save Our Efforts In Sap IntegrationGuo Albert
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionMazenetsolution
 
In Memory Unit Testing with Apache DbUnit
In Memory Unit Testing with Apache DbUnitIn Memory Unit Testing with Apache DbUnit
In Memory Unit Testing with Apache DbUnitMohammad Sabir Khan
 
Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsmichaelaaron25322
 
Intro to SpringBatch NoSQL 2021
Intro to SpringBatch NoSQL 2021Intro to SpringBatch NoSQL 2021
Intro to SpringBatch NoSQL 2021Slobodan Lohja
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkBill Lyons
 
Java EE Revisits GoF Design Patterns
Java EE Revisits GoF Design PatternsJava EE Revisits GoF Design Patterns
Java EE Revisits GoF Design PatternsMurat Yener
 
Performant Django - Ara Anjargolian
Performant Django - Ara AnjargolianPerformant Django - Ara Anjargolian
Performant Django - Ara AnjargolianHakka Labs
 
NoSQL Endgame LWJUG 2021
NoSQL Endgame LWJUG 2021NoSQL Endgame LWJUG 2021
NoSQL Endgame LWJUG 2021Thodoris Bais
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity FrameworkMahmoud Tolba
 
Managing Data in Jakarta EE Applications
Managing Data in Jakarta EE ApplicationsManaging Data in Jakarta EE Applications
Managing Data in Jakarta EE ApplicationsBuhake Sindi
 
DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply rem...
DevSecCon Singapore 2018 -  Remove developers’ shameful secrets or simply rem...DevSecCon Singapore 2018 -  Remove developers’ shameful secrets or simply rem...
DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply rem...DevSecCon
 

Similar to Dao example (20)

Data access
Data accessData access
Data access
 
Jdbc
JdbcJdbc
Jdbc
 
Utilized Code Gen To Save Our Efforts In Sap Integration
Utilized Code Gen To Save Our Efforts In Sap IntegrationUtilized Code Gen To Save Our Efforts In Sap Integration
Utilized Code Gen To Save Our Efforts In Sap Integration
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet Solution
 
Midao JDBC presentation
Midao JDBC presentationMidao JDBC presentation
Midao JDBC presentation
 
In Memory Unit Testing with Apache DbUnit
In Memory Unit Testing with Apache DbUnitIn Memory Unit Testing with Apache DbUnit
In Memory Unit Testing with Apache DbUnit
 
Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applications
 
Intro to SpringBatch NoSQL 2021
Intro to SpringBatch NoSQL 2021Intro to SpringBatch NoSQL 2021
Intro to SpringBatch NoSQL 2021
 
SSDT unleashed
SSDT unleashedSSDT unleashed
SSDT unleashed
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLink
 
Apache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI ToolboxApache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI Toolbox
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
 
Java EE Revisits GoF Design Patterns
Java EE Revisits GoF Design PatternsJava EE Revisits GoF Design Patterns
Java EE Revisits GoF Design Patterns
 
Performant Django - Ara Anjargolian
Performant Django - Ara AnjargolianPerformant Django - Ara Anjargolian
Performant Django - Ara Anjargolian
 
NoSQL Endgame LWJUG 2021
NoSQL Endgame LWJUG 2021NoSQL Endgame LWJUG 2021
NoSQL Endgame LWJUG 2021
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity Framework
 
Hybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbaiHybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbai
 
Hibernate notes
Hibernate notesHibernate notes
Hibernate notes
 
Managing Data in Jakarta EE Applications
Managing Data in Jakarta EE ApplicationsManaging Data in Jakarta EE Applications
Managing Data in Jakarta EE Applications
 
DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply rem...
DevSecCon Singapore 2018 -  Remove developers’ shameful secrets or simply rem...DevSecCon Singapore 2018 -  Remove developers’ shameful secrets or simply rem...
DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply rem...
 

More from myrajendra

More from myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
2. attributes
2. attributes2. attributes
2. attributes
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 
Properties
PropertiesProperties
Properties
 
Java.sql package
Java.sql packageJava.sql package
Java.sql package
 
Interface callable statement
Interface callable statementInterface callable statement
Interface callable statement
 
Interface result set
Interface result setInterface result set
Interface result set
 
Interface database metadata
Interface database metadataInterface database metadata
Interface database metadata
 
Interface connection
Interface connectionInterface connection
Interface connection
 

Recently uploaded

Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 

Recently uploaded (20)

Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 

Dao example

  • 1. Using JDBC in the Project (Project Architecture) http://rajjdbc.blogspot.in/
  • 2. Using JDBC in the Project (Project Architecture) http://rajjdbc.blogspot.in/
  • 3. Using JDBC in the Project (Project Architecture) http://rajjdbc.blogspot.in/
  • 4. Using JDBC in the Project (Project Architecture) http://rajjdbc.blogspot.in/
  • 5. Using JDBC in the Project (Project Architecture) http://rajjdbc.blogspot.in/
  • 6. Using JDBC in the Project (Project Architecture) http://rajjdbc.blogspot.in/
  • 7. Using JDBC in the Project (Project Architecture) http://rajjdbc.blogspot.in/
  • 8. Using JDBC in the Project (Project Architecture) http://rajjdbc.blogspot.in/
  • 9. Using JDBC in the Project (Project Architecture) http://rajjdbc.blogspot.in/
  • 10. Using JDBC in the Project (Project Architecture) http://rajjdbc.blogspot.in/
  • 11. Using JDBC in the Project (Project Architecture) http://rajjdbc.blogspot.in/
  • 12. Using JDBC in the Project (Project Architecture) with DAO Design Pattern http://rajjdbc.blogspot.in/
  • 13. Using JDBC in the Project (Project Architecture) with DAO Design Pattern http://rajjdbc.blogspot.in/
  • 14. Using JDBC in the Project (Project Architecture) with DAO Design Pattern http://rajjdbc.blogspot.in/
  • 15. Using JDBC in the Project (Project Architecture) with DAO Design Pattern http://rajjdbc.blogspot.in/
  • 16. Using JDBC in the Project (Project Architecture) with DAO Design Pattern http://rajjdbc.blogspot.in/
  • 17. Using JDBC in the Project (Project Architecture) with DAO Design Pattern http://rajjdbc.blogspot.in/
  • 18. Using JDBC in the Project (Project Architecture) with DAO Design Pattern http://rajjdbc.blogspot.in/
  • 19. Using JDBC in the Project (Project Architecture) with DAO Design Pattern http://rajjdbc.blogspot.in/
  • 20. Using JDBC in the Project (Project Architecture) with DAO Design Pattern http://rajjdbc.blogspot.in/
  • 21. Using JDBC in the Project (Project Architecture) with DAO Design Pattern http://rajjdbc.blogspot.in/
  • 22. Using JDBC in the Project (Project Architecture) with DAO Design Pattern http://rajjdbc.blogspot.in/
  • 23. Using JDBC in the Project (Project Architecture) with DAO Design Pattern http://rajjdbc.blogspot.in/
  • 24. Using JDBC in the Project (Project Architecture) with DAO Design Pattern http://rajjdbc.blogspot.in/
  • 25. Using JDBC in the Project (Project Architecture) with DAO Design Pattern http://rajjdbc.blogspot.in/
  • 26. What is Low Level Persistence Logic? • Low Level means it is specific to one type of dependent persistence logic • Persistence Logic: is responsible for accessing persistence Data • If I’m using low level persistence logic in Business Logic (i.e High Level Logic) so I can not connect to all the Back end servers. • To avoid this problem we have to use another layer , keep the persistence logic in a separate object, that object is nothing but a Data Access Object (DAO). • • SO here DAO is a Design Pattern, Design Pattern which gives a solution for a problem. • (Example: I’m facing a problem, I will try to interact with a friend who is already faced the problem because he will have ready made solution for that problem, no need to waste my time to solve the problem, because already ready made solution (design pattern) is available http://rajjdbc.blogspot.in/
  • 27. What is Low Level Persistence Logic? http://rajjdbc.blogspot.in/
  • 28. Introducing DAO • When it comes into the project (enterprise application) we need to concentrate in optimizing the code, making the more reusable, and also testable. • The DAO is the most common pattern implemented into the enterprise applications. http://rajjdbc.blogspot.in/
  • 29. What is a Pattern? • Pattern is a three part document that describes the context (situation), reoccurring problem and the best solution for the problem in the given context (situation). • The software patterns are categorized into multiple type for convenience in learning and applying. • The design patterns is one of the category. This lists the patterns describing the problems related to design and development of the software applications http://rajjdbc.blogspot.in/
  • 30. THE DAO DESIGN PATTERN: • • As the title describes this is a design pattern • Context (situation): • We want to create enterprise Application with reasonable business logic having a requirement of accessing multiple (variety) of datastore and /or found that may have a requirement of migrating from one type of data store (database) to other. Easy to migrate between the different types of data stores. That is in my application I want to connect to LDAP to take credentials, same application I want to connect to File Systems to accept login details. • Problem: • We want to separate the low-level persistence (data access) logic from Business Logic. But this so this solution leaves a problem that is how do you separate in a best way? Thus this solution we kept in a problem. • Forces: (Why): • We want to have a proper responsibility division that is: • (a) improves the quality of the system. • (b) reduces the cost and time for the development • To enable unit testing, make the system more comfortable for testing. • Easy to migrate between the different types of data stores. • Solution: • Implement the low-level persistence logic into a separate object, exposing the data access operations through high-level API to the service layer. http://rajjdbc.blogspot.in/
  • 31. What is DAO ? • Ans: DAO is a design pattern that describes separating the low-level persistence logic from the business logic, implementing into a separate (independent) object. • • Note: this special object introduced implementing the DAO pattern is also refered as a DAO i.e: Data Access Object http://rajjdbc.blogspot.in/
  • 33. • From this discussion and the above architecture we understand JDBC is used for implementing the DAO in Java for accessing the tabular data store http://rajjdbc.blogspot.in/
  • 34. Use Case diagram of our project http://rajjdbc.blogspot.in/
  • 35. Implementing DAO Design Pattern in our project http://rajjdbc.blogspot.in/
  • 36. Implementing the Data Access Layer for ‘CreateEmployee’ use case of ‘Employee Management System (EMS). • For Example: • Implementing the Data Access Layer for ‘CreateEmployee’ use case of ‘Employee Management System (EMS). • • //EmployeeDAOI.java • package com.st.ems.dao; • public interface EmployeeDAOI • { • void save(int eno,String name, double sal, int dno); • //we will change this struture later • //we will add some more methods as we proceed • } • • • //EmployeeDAO.java • package com.st.ems.dao.jdbc; • import com.st.ems.dao.EmployeeDAOI; • import java.sql.*; • import java.util.*; • public class EmployeeDAO implements EmployeeDAOI • { • public void save(int eno, String name,double sal, int dno) • { • //this method is responsible for saving the given details into emp table • //to do: execute the following SQL • String sql="insert into emp values("+eno+",'"+name+",',"+sal+","+dno+")"; http://rajjdbc.blogspot.in/
  • 37. • //how to execute? • //use JDBC • //Write this Connection con=null here only to make visible to all the blocks • Connection con=null;//null is necessary whn u r declaring as a local variable • try • { • //step 1.1 • String driverClassName="oracle.jdbc.driver.OracleDriver";//here we are using oracle driver • Class c=Class.forName(driverClassName); • Driver d=(Driver)c.newInstance(); • //step 1.2 • String jdbcUrl="jdbc:oracle:thin:@localhost:1521:XE"; • Properties p=new Properties(); • p.put("user","system"); • p.put("password","manager"); • //Connection con=null;//i can not use con ref variable in finally block as it is local to this • block • • http://rajjdbc.blogspot.in/
  • 38. • con=d.connect(jdbcUrl,p); • //step2 • Statement st=con.createStatement(); • //step3 • st.executeUpdate(sql); • • • }//end of try block • catch(Exception e) • { • e.printStackTrace(); • //to report the error, we will set run time error • throw new RuntimeException(e); • } • finally • { • try • { • //step 4: • con.close(); • • }//try • catch(Exception e){} • }//finally • • • }//save • }//class http://rajjdbc.blogspot.in/
  • 39. • /* now we are writing Tese case for DAO object [that is save()] for this we have to use JUNIT but • we are using main() for this application • */ • //EmployeeDAOTestCase.java • import com.st.ems.dao.jdbc.EmployeeDAO; • import com.st.ems.dao.EmployeeDAOI; • • • public class EmployeeDAOTestCase • { • private EmployeeDAOI edao; • public void testsave() • { • edao.save(102,"e102",20000,20); • System.out.println("Details saved"); • } • public static void main(String s[]) • { • EmployeeDAOTestCase test=new EmployeeDAOTestCase(); • test.edao=new EmployeeDAO(); • test.testsave();//here Driver object is created • //test.testsave();//here 2nd Driver object is created but one Driver object is enought to handle • //multiple request from diffrent clients, connections as it is a Thread -safe • } • } http://rajjdbc.blogspot.in/
  • 40. • /* • D:materialjava(E DRIVE)javaAdvJavajdbcDAO>javac -d . *.java • D:materialjava(E DRIVE)javaAdvJavajdbcDAO>D:materialjava(E • DRIVE)javaAdvJavajdbcDAO>set classpath=C:oraclexeappor • acleproduct10.2.0serverjdbclibojdbc14.jar;.; • D:materialjava(E DRIVE)javaAdvJavajdbcDAO>java EmployeeDAOTestCase • Details saved • */ http://rajjdbc.blogspot.in/
  • 41. Work flow of our program http://rajjdbc.blogspot.in/
  • 42. Q: is our DAO created efficient? • Ans: No, we need to multiple changes. Let us look into all of them one after the other • In the EmployeeDAO created earlier the save() method is programmed to create a new instance (object) of Driver class on every request, which is not effective. • Considering the following points with respect to the Driver: • The Driver object is Thread-safe means Driver object performs consistently even on concurrent requests from multiple threads • A single instance of Driver can be used to create multiple connections because it is Thread-safe. If we create the multiple instances of Driver class, unnecessarly garbage is stored into the memory, and performance becomes slow. • Considering these points a single instance of Driver is enough for an application per data base. http://rajjdbc.blogspot.in/
  • 44. • (INTRODUCTION TO DRIVER MANAGER) • That means we want to redesign the DAO such that it should work with single instance of Driver class irrespective of the number of clients and requests. • To address this requirements JDBC introduces DriverManager class • Q: What is Driver Manager class? • The java.sql.DriverManager is a factory class that is designed to create the Connection Managing the Driver objects. • Why DriverManager? • Ans: to centralize the code( means connect() method) creating the Connection using the Driver object. So that we can avoid multiple instances (objects) of a Driver class to create. Here the code means connect() method. • • Q: How DriverManager functions? • We know that the basic functionality of the DriverManager is to create the Connection managing the Driver object. The getConnection() method will create connection using registered Driver object. • • Working with DriverManager • Fig: DriverManager FactoryClass(.JPG • The following two steps are involved in doing this: • Step1: Register the Driver to DriverManager • Step2: Invoke the getConnection() to get the Connection • http://rajjdbc.blogspot.in/