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
Disadvantages of JDBC
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
Disadvantages of ORM
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: JDBC vs ORM View All Comments
Post your Comment