Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Struts implementing DAO
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


virgo25
implementing DAO
2 Answer(s)      6 years ago
Posted in : Struts



Advertisement
View Answers

December 29, 2008 at 1:46 AM


Hi friend,


Java DAO Implementation
This tutorial shows, how to create the source code of Dao and DaoImpl class.
The Data Access Object (DAO) is an important component in business applications. 
Business applications almost always need access to data from relational or object databases and the Java platform offers many techniques for accessing this data. 
The Data Access Object design pattern provides a technique for separating object persistence and data access logic from any particular persistence mechanism or API.
The Java Database Connectivity (JDBC) API, provides the capability to execute SQL queries against a database and then fetch the results, one column at a time.
The Java DAO approach provides flexibility to change an application's persistence mechanism over time without the need to re-engineer application logic that interacts with the Data Access Object tier.
The Data Access Object design pattern also provides a simple, consistent API for data access that does not require knowledge of JDBC, EJB, Hibernate, or Spring interfaces.
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.

Source Code of Dao.java
package com.roseindia.portal.dao;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import java.util.List;

import com.roseindia.portal.model.*;

/**
 * @author Sandeep Kumar Suman
 */

@Transactional (propagation = Propagation.REQUIRED, readOnly = false)

public interface Dao{

    public List<Emp> findByName(String name);
    
  public void addEmp(Emp user);

  public void updateEmp(Emp chatEmp);

  public List<Emp> loginEmp(String username, String password);
  
  public void deleteEmp(Emp removeEmp);

}

---------------------------


December 29, 2008 at 1:47 AM


Source Code of DaoImpl.java
package com.roseindia.portal.dao.impl;

import com.roseindia.portal.dao.*;
import javax.persistence.EntityTransaction;


import java.util.*;
import java.text.*;
import java.util.ArrayList;
import java.util.Collection;
import java.sql.*;

import javax.persistence.Persistence;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.roseindia.portal.dao.BaseDao;
import com.roseindia.portal.model.*;

import org.springframework.orm.jpa.vendor.HibernateJpaDialect;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

/**
* @author Sandeep Kumar Suman
*/

@Transactional (propagation = Propagation.REQUIRED, readOnly = false)
public class DaoImpl implements Dao {


public List<Emp> findByName(String name){
Query query = this.getEntityManager().createQuery("select u FROM
Emp u where u.userName='" + name +"'");
return query.getResultList();
}

private EntityManager entityManager;
/**
* Set the JPA EntityManager to use.
*/
@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}

/**
* Return the JPA EntityManager to use.
*/
public EntityManager getEntityManager() {
return entityManager;
}

public void addEmp(Emp user){
this.getEntityManager().persist(user);
}

public void updateEmp(Emp user){
this.getEntityManager().merge(user);
}

public List<Emp> loginEmp(String username, String password){
System.out.println("Login Emp in Emp Service DAO");
Query query = this.getEntityManager().createQuery("select u FROM
Emp u where u.userName='" + username +"' and u.password='" + password +"'");
return query.getResultList();
}

public void deleteUser(User removeUser){
System.out.println("Removing User: "+removeUser.getFirstName());
this.getEntityManager().remove(removeUser);
}
}
---------------------------------------------------

Visit for more information:

http://www.roseindia.net/struts/struts2/

Thanks


Related Tutorials/Questions & Answers:
implementing DAO - Struts
implementing DAO  Hi Java gurus I am pure beginner in java..., exam in 3 days, and just now i found out our lecturer post a demo on DAO... divided into DAO factory Impl,employeeDAOImpl,DAOFactory,EmployeeDAO. "I strongly
DAO Classes
DAO Classes  login page code for Dao classes
Advertisements
DAO Example
DAO Example  Dear Friends Could any one please give me any example of DAO application in struts? Thanks & Regards Rajesh
DAO in Struts
DAO in Struts  Can Roseindia provide a simple tutorial for implementation of DAO with struts 1.2? I a link already exits plz do tell me. Thank you
DAO - JDBC
DAO  what is dao ? and how to use it?  Hi Friend, The DAO is a pattern that provides a technique for separating object persistence and data access logic from any particular persistence mechanism or API. Thanks
doubt on DAO's
doubt on DAO's  hai frnds.... can anyoneexplain about how... our own plugin????? and please help me. how to use dao s while integrating struts with hibernate..??? actually what is the purpose of dao's ????? please help
doubt on DAO's
doubt on DAO's  hai frnds.... can anyoneexplain about how... our own plugin????? and please help me. how to use dao s while integrating struts with hibernate..??? actually what is the purpose of dao's ????? please help
dao pack
dao pack  package com.tsi.dao; import java.sql.*; import com.tsi.constants.*; public class DaoPack { public static Connection conn = null; public static Connection createConnection() { try
dao pack
dao pack  package com.tsi.dao; import java.sql.*; import com.tsi.constants.*; public class DaoPack { public static Connection conn = null; public static Connection createConnection() { try
dao
Implementing Interface
Implementing Interface  interface Mat { void read( ); void display( ); } Create a class Matrix by implementing interface Mat. Derive class MatrixOp from Matrix and provide functions to add and multiply two matrices. Also derive
Implementing Vectors.
Implementing Vectors.  Create a class Student which stores Name ,Rollno and Grandtotal of a student. Use class Vector to maintain an array of students in the descending order of the Grand_total. Provide the following functions 1
CRUD DAO
CRUD DAO  how to create dao for create,read,update and delete?   /* *ConnectionManager * * *Version:1.0 * *Date:25-Nov-2011 * */ package com.student.dao; import java.sql.*; import org.apache.log4j.Logger
spring DAO module turorial
spring DAO module turorial  how to integrate springDAO and spring webMVC
implementing security - Security
implementing security  wanna learn cyptography in java...how must i proceed
Implementing FTP in Java Code
Implementing FTP in Java Code  Hi, My job is to write a program in Java in my project. I have to implement FTP in my Java Code. Share me some of the code of Implementing FTP in Java Code. Thanks   Hi, Apache ftp
code for implementing sale purchase
code for implementing sale purchase  i have two tables in database. in one table i have stock of sms and further details and other table is for customer .if customer purchases my sms then the value will be deduct from my table
Implementing voice commands
Implementing voice commands  Am trying to write a java program to implement voice commands within a windows platform using preferably java (though any language will do). I would be glad for any tips and procedures that would help
DAO DTO design pattern
DAO DTO design pattern  Hi,using dao and dto i want to perform insert,update and delete operation.and the data should navigate from 1 frame 2 another.that page should b smthng like this: <%@ page language="java" import
DAO DTO design pattern
DAO DTO design pattern  Hi,using dao and dto i want to perform insert,update and delete operation.and the data should navigate from 1 frame 2 another.that page should b smthng like this: <%@ page language="java" import
DAO DTO design pattern
DAO DTO design pattern  Hi,using dao and dto i want to perform insert,update and delete operation.and the data should navigate from 1 frame 2 another.that page should b smthng like this: <%@ page language="java" import
DAO DTO design pattern
DAO DTO design pattern  Hi,using dao and dto i want to perform insert,update and delete operation.and the data should navigate from 1 frame 2 another.that page should b smthng like this: <%@ page language="java" import
how to create dao
how to create dao   code1: package com.dao; import java.sql.*; import com.beans.*; public class DbAccess { public void createStudent(SampleBean sampleBean) throws SQLException { Connection con=null; try
DAO,DTO,VO Design patterns
DAO,DTO,VO Design patterns  explain dao,dto,vo design patterns in strut 1.3?   Data Access Object (DAO) pattern is the most popular design patterns. It is used when you want to separate your presentation code from
DAO Layer explained
DAO Layer explained       In this section we will explain you the DAO Layer of our application.   DAO Layer Explained   DAO stand for Data
how to login form through spring dao module
how to login form through spring dao module  here i want to chek user details in database through form by using spring dao module.please give me some reference example to me
Implementing Digits restriction Using JQuery
Implementing Digits restriction Using JQuery  Hi Sir I have following field in my html form : <div>Age<input type="text" name="quantity" id="quantity" /></div> I want to implement two things : 1
Exception handling in super and subclass while implementing inheritance,,?
Exception handling in super and subclass while implementing inheritance,,?  How to implement Superclass Exceptions with SubClass while implementing Inheritance concept in core java.? Please answer for this with sample code
Creating Data Access Object (DAO) Design Pattern
Creating Data Access Object (DAO) Design Pattern Data Access Object... code contains in  DAO and it provides a simple interface to access the data. In DAO you need to create the Connection factory class. This class contains
Problem to get connection from DAO class to JDBC
Problem to get connection from DAO class to JDBC  package controller; import java.sql.Connection; import java.sql.DriverManager; public class ConnectionProvider { private static Connection con=null; //static Connection
 

 

 

DMCA.com