Data Access Design Pattern what is it &how to use it .. ????


General J2EE: Data Access Design Pattern what is it &how to use it .. ????

  1. this is the prob...
    Context ctx = new InitialContext();
    javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup ("nehalDS");

    Connection con = ds.getConnection();
    Statement stmt = con.createStatement();
    stmt.execute(some query");
    ResultSet rs = stmt.getResultSet();

    the same code i am using in all the jsps through out the site to access the oracle database. I need to abstract it into some reuseable pattern.i found out Data Access Object pattern is the solution but how to use it... can any1 help me with some small example on which i can built up...
  2. If I understand right you are looking for a replaceable persistence layer ? You might look into EJB Design Patterns of Floyd Marinescu and search for Data Access Command Bean pattern. It's lightweight and extremely effective unless you have lotsa domain objects, situation when your persistence layer becomes clutterd with small classes... but it's your choice at last

    Dunno if this helps, sorry. you might be a little more specific in your next note ... :-)
  3. DAO Pattern -

    You should also consider using the MVC pattern instead of having your JSPs talk directly to your DB. JSP's should simply present data w/o needing to know where it came from.