Click to See Complete Forum and Search --> : Servlet vs POJO


scottjsn
01-23-2008, 07:20 PM
If a Servlet class requires information from a database, then the servlet container provides JDBC access to the class.

Now if a non-servlet class (POJO) requires information from a database, "who" will provide JDBC access to the class?

Thanks


Scott

chazzy
01-26-2008, 12:31 PM
Scott,

I can't help but wonder why you're asking all of these 1 off questions, and then never responding to the thread. :-)

As to answer your question, there are many ways to do similar things. Have you ever heard of EJB's? They're pojo's, but they get the database connections injected. They run in containers though. For non container items, perhaps in a GUI, then maybe you would use a 3rd party provider to inject the needed components. Also, since JPA became a separate specification from EJB, you can inject EntityManager's into non container classes, depending on how your EntityManager provider behaves (for example, I know this works in OpenJPA and Hibernate).

fahlyn
01-27-2008, 08:38 AM
you could also use spring (http://www.springframework.org/documentation). Spring will allow you to inject dependencies (such as database connections) into pojos. It's extremely easy to use and to setup.