Posts

Spring – ORM Framework

                Spring – ORM Framework Spring-ORM  is a technique or a Design Pattern used to access a relational database from an object-oriented language. ORM (Object Relation Mapping) covers many persistence technologies. They are as follows: JPA(Java Persistence API):  It is mainly used to persist data between Java objects and relational databases. It acts as a bridge between object-oriented domain models and relational database systems. JDO(Java Data Objects):  It is one of the standard ways to access persistent data in databases, by using plain old Java objects (POJO) to represent persistent data. Hibernate –  It is a Java framework that simplifies the development of Java applications to interact with the database. Oracle Toplink, and iBATIS:  Oracle TopLink is a mapping and persistence framework for Java development.

Spring – RowMapper Interface with Example

  RowMapper Example | Fetching records by Spring JdbcTemplate we can use RowMapper interface to fetch the records from the database using  query()  method of  JdbcTemplate  class. In the execute of we need to pass the instance of RowMapper now. Syntax of query method using RowMapper public T query(String sqlQuery, RowMapper<T> rowMapper) RowMapper Interface RowMapper  interface allows to map a row of the relations with the instance of user-defined class. It iterates the ResultSet internally and adds it into the collection. So we don't need to write a lot of code to fetch the records as ResultSetExtractor. Advantage of RowMapper over ResultSetExtractor RowMapper saves a lot of code becuase it internally adds the data of ResultSet into the collection. Method of RowMapper interface It defines only one method mapRow that accepts ResultSet instance and int as the parameter list. Syntax of the method is given below: public T mapRow(ResultSet rs, int rowNumb...

Spring JdbcTemplate

  Spring JdbcTemplate Spring  JdbcTemplate  is a powerful mechanism to connect to the database and execute SQL queries. It internally uses JDBC api, but eliminates a lot of problems of JDBC API. Problems of JDBC API The problems of JDBC API are as follows: We need to write a lot of code before and after executing the query, such as creating connection, statement, closing resultset, connection etc. We need to perform exception handling code on the database logic. We need to handle transaction. Repetition of all these codes from one to another database logic is a time consuming task. Spring JdbcTemplate eliminates all the above mentioned problems of JDBC API. It provides you methods to write the queries directly, so it saves a lot of work and time. Spring Jdbc Approaches Spring framework provides following approaches for JDBC database access: JdbcTemplate NamedParameterJdbcTemplate SimpleJdbcTemplate SimpleJdbcInsert and SimpleJdbcCall JdbcTemplate class It is the central c...