wood burning stoves*
The moose likes JDBC and the fly likes Making a JEE application without using ORM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Making a JEE application without using ORM" Watch "Making a JEE application without using ORM" New topic
Author

Making a JEE application without using ORM

Daniel Sulkin
Greenhorn

Joined: May 02, 2012
Posts: 1

Hello,

I'm creating a website (with servlets & jsp) and for now I don't want to use an ORM tool like JPA or Hibernate but do it with JDBC.
I'm confused about how this works; I also want to follow the MVC pattern.
Where should I put all the code that accesses the DB?

Basically I'm doing it like this:

1) User sends a request for a page
2) The request goes to the controller
3) I query the DB for the content of the page requested
4) Set an attribute with the results from the DB
5) Forward the request and display the results to the end user

Should I make a java bean that represents a page (title, content), instantiate one and pass the object to the controller (basically the model)? Also, since I'm creating a JDBC resource and a connection pool in glassfish, I need to close the connection every time and connect to the DB again when another request comes in? How can I use connection pooling to avoid this overhead of opening/closing connections?
Pongsakorn Semsuwan
Ranch Hand

Joined: May 15, 2011
Posts: 34

Mine usually goes like this.

Servlet - get request and manipulate with input parameter
Service - apply your business logic
DAO - works with DB
Model - usually represent DB's table
FormBean - represent page

I open connection and commit transaction at service layer. Service layer will call DAO which is where you work with your DB (INSERT, UPDATE etc..).
I open connection and commit at service layer because some transaction might use more than one DAO.

For what you are searching for, one of my application store DBConnection in ThreadLocal
http://veerasundar.com/blog/2010/11/java-thread-local-how-to-use-and-code-sample/




A web application developer wannabe from Thailand
My StartUp : http://www.dreamlog.co
Blog : http://pongsakornsemsuwan.wordpress.com
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Making a JEE application without using ORM