File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Need Help on DAO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Need Help on DAO " Watch "Need Help on DAO " New topic
Author

Need Help on DAO

Mark Henryson
Ranch Hand

Joined: Jul 11, 2005
Posts: 200
Hi all,

I am in fond of learning DAO and trying to implement it in my project. I don't know where to start. Before that I'll just brief my expertise level. I know Core Java and I had done 4 to 5 projects in JSP and Servlets. If I want to learn DAO, what are the things I have to learn before hand. Because While I try to learn DAO in some tutorial, I came to know lot of new things came which I never learnt like JTA, JDO, EJB, JNDI ....

And I want some basic tutorial for learning DAO, I had searched in google, but I didn't find any simple or basic tutorial for beginners. The one from IBM and Sun Site seems to not clear for me. Any other tutorial/links/ will be useful and also suggest, for learning DAO, I have to learn any other thing before hand or is't ok if Core Java,jsp and servlet is sufficient.
Reid M. Pinchback
Ranch Hand

Joined: Jan 25, 2002
Posts: 775
If you know servlets, and you want to learn how to write and use DAOs, the easiest next step is to be sure you understand how to write JDBC code, since you can't access a database without some form of code to handle the database interaction. There are obviously ways you can write DAOs without JDBC (JDO, Spring, Hibernate, ...), but from the standpoint of learning how this technology works, I think it makes sense to at least try it in JDBC first. All the other options internally will be using JDBC in some form or another; at least this way you'll have a mental model for what is going on when you shift to more powerful/more convenient options.


Reid - SCJP2 (April 2002)
Mark Henryson
Ranch Hand

Joined: Jul 11, 2005
Posts: 200
Hi,
Thanks for your reply.
I know JDBC to certain extend. Now I am using Connection pooling for getting the connection. I have written one separate class for connection pooling. For example: If I want want to add the customer details in the database, I will write one servlet for Customer, which will have insert query for inserting into DB That are all working fine. For deletion/Modification, I will use Delete/Update query in the Customer Servlet itself.

So, I know JDBC also to certain extend. I am not find any good tutorial like step by step procedural of how to write the DAO pattern. Other wise, I want some good books for DAO pattern. pls suggest some good books for DAO for beginners.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Have you looked at Core J2EE Patterns - Data Access Object.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Pj Murray
Ranch Hand

Joined: Sep 24, 2004
Posts: 194
Originally posted by Reid M. Pinchback:
If you know servlets, and you want to learn how to write and use DAOs, the easiest next step is to be sure you understand how to write JDBC code, since you can't access a database without some form of code to handle the database interaction. There are obviously ways you can write DAOs without JDBC (JDO, Spring, Hibernate, ...), but from the standpoint of learning how this technology works, I think it makes sense to at least try it in JDBC first. All the other options internally will be using JDBC in some form or another; at least this way you'll have a mental model for what is going on when you shift to more powerful/more convenient options.



This is excellent advise. Even if you decide to use an ORM solution later on, you really should understand JDBC. You'll find many situations where straight JDBC DAOs are the best choice.


PJ Murray -
Michael Duffy
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
Originally posted by Mark Henryson:
Hi,
Thanks for your reply.
I know JDBC to certain extend. Now I am using Connection pooling for getting the connection. I have written one separate class for connection pooling. For example: If I want want to add the customer details in the database, I will write one servlet for Customer, which will have insert query for inserting into DB That are all working fine. For deletion/Modification, I will use Delete/Update query in the Customer Servlet itself.

So, I know JDBC also to certain extend. I am not find any good tutorial like step by step procedural of how to write the DAO pattern. Other wise, I want some good books for DAO pattern. pls suggest some good books for DAO for beginners.



You should not be using a connection pool that you wrote. Better to use a production-quality one like Jakarta's DBCP.

Servlets should not have queries in them. What will you do if you decide to reuse those database actions outside a web context?

How hard can it be? All DAOs have a similar basis:



You'll have more find methods for each WHERE clause.

No books. Google for it - it's on the Web.


%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Help on DAO