Wednesday, October 8, 2008

Pros and Cons JDBC and Hibernate Step 15

There are different ways of connecting to a database. I am going to talk about 3 of them.

1) You can connect using a JDBC connection within your Application

2) You can connect using a JDBC with your Application Server (Tomcat)

3) You can connect using Hibernate (Relational Mapping)


**************************************************
1) Opening a JDBC connection within your application is easier to do. However, you have to manage the amount of connections to the database within your application. You will have to open and close a connection each time you query the database. This usually is unnecessary overhead.
Go To JDBC Example Connection 1


2) Creating a connection within the Application Server can require more configuration. However, for optimum performance of database-intensive applications, the Application Server should manage the JDBC connection pool. Further, object pooling in the Application Server will also help to reduce the garbage collection load.
Go To JDBC Exampe Connection 2

3) Hibernate is much more complicated to use, but allows you to map the database to objects within your Application. If you are building a complicated system, then Hibernate might be the way to go. If your system only has a small amount of tables, then the JDBC connection might be the way to go. Hibernate also has some restrictions when it comes to querying the database. One example is using the relevance search in SQL Server. You are not able to do that in hibernate.

Go To Hibernate Example Connection 3


In my next posts, I will show you how to obtain database connections with those three options we just discussed.

2 comments:

Stells November 21, 2008 8:23 AM  

Oooo!!! I have been looking for methods to get JDBC connection from Hibernate for ages by now. Waiting for your new, promised ;), post :)
Thank you!

Greg November 24, 2008 11:09 AM  

I have posts that demonstrate three different ways to connect to the database. Hibernate is primarily used to map your objects to your database. I have example posts that can show you how to do direct query to your database.