Explain JDBC and Hibernate in java.

in #jdbc7 years ago

What is JDBC ?

edited.jpg

JDBC stands for Java Database Connectivity. It is a free open source application programming interface for Java that enables applications to access databases. It enables developers to create queries and update data to a relational database using the Structured Query Language (SQL).

JDBC Workflow:

Java_jdbc.png

  1. Open a database connection
  2. Send SQL queries to database using a JDBC driver
  3. JDBC driver connects to the database
  4. Execute the queries to get the result set
  5. Send the data to the application via the driver manager
  6. When results are returned, it processes the data
  7. Finally, the connection is closed

What is Hibernate ?

Hibernate-ORM.png

Hibernate is a free, open source object-relational mapping library for Java designed to map objects to an RDBMS and to implement the object-oriented programming concepts in a relational database.

Hibernate Workflow:

hibernate2.png

  1. Unlike JDBC, Hibernate connects with the database itself and uses HQL (Hibernate Query Language) to execute the queries, then maps the results to Java objects.
  2. The results are mapped to objects based on the properties given in the Hibernate configuration XML file.
  3. The database connection from an application is created using the session, which also helps in saving and retrieving the persistent object.
  4. Session factory is an interface that helps to create an instance of a session. There must be only one session factory per database. For example, if you are using MySQL and Oracle in your application, one session factory for MySQL and one session factory for Oracle is maintained. There will not be more than one session factory for MySQL alone.
Sort:  

Hi! I am a robot. I just upvoted you! I found similar content that readers might be interested in:
https://dzone.com/articles/15-reasons-to-choose-hibernate-over-jdbc

java program is the best program in 2010