Home Jpa JDBC vs ORM
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

JDBC vs ORM

Advertisement
In this section we will examine the differences and similarities between JDBC and ORM technologies.

JDBC vs ORM

     

In this section we will examine the differences and similarities between JDBC and ORM technologies. Both these technologies are used to save the data into persistence storage for future reference.

What is JDBC?

JDBC stands for Java Database Connectivity, is a set of Java API for accessing the relational databases from Java program. The Java API enables the programmers to execute the SQL statements against the JDBC complaint database.

JDBC allows the programmers to quickly develop small Java applications that interact with the databases. To develop an application programmer has to develop the code to connect to the database and then write the code to execute the query. Once the query is successfully executed and result is retrieved from the database, programmer can read the data programmatically from the result set object. Here is the simple example of JDBC example program.

 

import  java.sql.*;

public class  AllTableName{
   public static void  main(String[] args) {
   System.out.println( "Listing all table name in Database!" );
   Connection con =  null ;
   String url =  "jdbc:mysql://localhost:3306/" ;
   String db =  "jdbctutorial" ;
   String driver =  "com.mysql.jdbc.Driver" ;
   String user =  "root" ;
   String pass =  "root" ;
   try {
   Class.forName(driver);
   con = DriverManager.getConnection(url+db, user, pass);
   try {
   DatabaseMetaData dbm = con.getMetaData();
   String[] types = { "TABLE" };
   ResultSet rs = dbm.getTables(null,null, "%" ,types);
   System.out.println( "Table name:" );
   while  (rs.next()){
   String table = rs.getString( "TABLE_NAME" );
   System.out.println(table);
   con.close();
   }
   }
   catch  (SQLException s){
   System.out.println( "No any table in the database" );
   }
   }
   catch  (Exception e){
   e.printStackTrace();
   }
   }
}

Above program retrieves the names of all tables present in the database and then displays on the console.

Advantages of JDBC

  • Clean and easily for small programs
  • JDBC provides good performance with large amount of data
  • Small JDBC programs can be developed very easily
  • Very good for small applications

Disadvantages of JDBC

  • JDBC is not easily if it is used in large projects. There is a big programming overhead.
  • Programmer must hardcode the Transactions and concurrency code in the application.
  • Handling the JDBC connections and properly closing the connection is also a big issue. Properly closing the connection is must.
  • JDBC is not good for big applications

What is ORM?

ORM stands for Object Relational Mapping, is another technology to access the data databases. Here business object is directly mapped to the database tables with the help of ORM framework.

Here are the benefits of ORM technology

  • No need to deal with the SQL Queries to save and retrieve the data
  • Simple configuration
  • Standardized API to persist the business objects
  • Fast development of application
  • Concurrency support
  • Excellent cashing support for better performance of the application
  • Injected transaction management
  • Configurable logging
  • Easy to learn and use

Disadvantages of ORM

  • Slow performance in case of large batch updates
  • Little slower than JDBC 
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 21, 2008

Ask Questions?    Discuss: JDBC vs ORM   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com