100000380
Points
Questions
185
Answers
186
-
When we compile a java file, we get a class file which contains bytecode. JVM converts bytecode to executable instructions as per the respective operating system. Executable instructions are different for each operating system. So, JVM is different for every operating system.
The platform dependency of JVM makes Java platform independent.
This answer accepted by JavaNinja. on 19th September 2018 Earned 15 points.
- 3640 views
- 2 answers
- 0 votes
-
Spring and Hibernate can integrate using Spring’s SessionFactory called LocalSessionFactory. The integration process is of 3 steps.
- Configure the Hibernate SessionFactory
- Extend your DAO Implementation from HibernateDaoSupport
- Wire in Transaction Support with AOP
This answer accepted by JavaNinja. on 19th September 2018 Earned 15 points.
- 1436 views
- 1 answers
- 0 votes
-
There are two approaches to Spring’s Hibernate integration:
- Inversion of Control with a HibernateTemplate and Callback
- Extending HibernateDaoSupport and Applying an AOP Interceptor
This answer accepted by JavaNinja. on 19th September 2018 Earned 15 points.
- 1707 views
- 1 answers
- 0 votes
-
Spring supports the following ORM’s :
- Hibernate
- iBatis
- JPA (Java Persistence API)
- TopLink
- JDO (Java Data Objects)
- OJB
This answer accepted by JavaNinja. on 19th September 2018 Earned 15 points.
- 1583 views
- 1 answers
- 0 votes
-
The update() method in JdbcTemplate can be used to perform insert, update and delete operations as shown below:
- Insert Operation
this.jdbcTemplate.update("insert into employee (empid, empname) values (?, ?)", 1000L, "James");
- Update Operation
this.jdbcTemplate.update("update employee set empname = ? where empid = ?", "Jeff", 1000L);
- Delete Operation
this.jdbcTemplate.update("delete from employee where empid = ?", Long.valueOf(empId));
This answer accepted by JavaNinja. on 19th September 2018 Earned 15 points.
- 2031 views
- 1 answers
- 0 votes
-
The following code snippet explain how JdbcTemplate can be used for querying objects.
Employee is the name of the class which is mapped to employee table in the database.
..... List<Employee> employees = this.jdbcTemplate.query( "select empid, empname from employee", new RowMapper<Employee>() { public Employee mapRow(ResultSet rs, int rowNum) throws SQLException { Employee emp = new Employee(); emp.setEmpId(rs.getInteger("empid")); emp.setEmpName(rs.getString("empname")); return emp; } }); .....
This answer accepted by JavaNinja. on 19th September 2018 Earned 15 points.
- 1539 views
- 1 answers
- 0 votes
-
Spring’s JdbcTemplate class is the central class to interact with a database through JDBC. It handles the creation and release of resources. It performs the basic tasks of the core JDBC workflow such as statement creation and execution, leaving application code to provide SQL and extract results.
The JdbcTemplate class executes SQL queries, update statements and stored procedure calls, performs iteration over ResultSets and extraction of returned parameter values. It also catches JDBC exceptions and translates them to the generic, more informative, exception hierarchy defined in the org.springframework.dao package.
This answer accepted by JavaNinja. on 19th September 2018 Earned 15 points.
- 1556 views
- 1 answers
- 0 votes
-
There are several approaches for JDBC database access in Spring and they are:
-
- JdbcTemplate is the classic Spring JDBC approach and the most popular. This “lowest level” approach and all others use a JdbcTemplate under the covers.
-
- NamedParameterJdbcTemplate wraps a JdbcTemplate to provide named parameters instead of the traditional JDBC”?” placeholders. This approach provides better documentation and ease of use when you have multiple parameters for an SQL statement.
-
- SimpleJdbcInsert and SimpleJdbcCall optimize database metadata to limit the amount of necessary configuration. This approach simplifies coding so that you only need to provide the name of the table or procedure and provide a map of parameters matching the column names. This only works if the database provides adequate metadata. If the database doesn’t provide this metadata, you will have to provide explicit configuration of the parameters.
-
- RDBMS Objects including MappingSqlQuery, SqlUpdate and StoredProcedure requires you to create reusable and thread-safe objects during initialization of your data access layer. This approach is modeled after JDO Query wherein you define your query string, declare parameters, and compile the query. Once you do that, execute methods can be called multiple times with various parameter values passed in.
This answer accepted by JavaNinja. on 19th September 2018 Earned 15 points.
- 1499 views
- 1 answers
- 0 votes
-
-
When using the Spring JDBC framework the burden of resource management and error handling is reduced. So developers only need to write the statements and queries to get the data to and from the database. JDBC can be used more efficiently with the help of a template class provided by Spring framework, called JdbcTemplate.
This answer accepted by JavaNinja. on 19th September 2018 Earned 15 points.
- 1484 views
- 1 answers
- 0 votes
-
Spring provides a convenient translation from technology-specific exceptions like SQLException to its own exception class hierarchy with the DataAccessException as the root exception. These exceptions wrap the original exception so that there is no loss of information.
Spring wraps JDBC exception and Hibernate-specific exceptions, converting them from proprietary, checked exceptions to a set of focused runtime exceptions. This allows one to handle most persistence exceptions, which are non-recoverable, only in the appropriate layers, without having much boilerplate catch-and-throw blocks and exception declarations in DAOs. This is true for the various template classes in Spring support for various ORM frameworks.
This answer accepted by JavaNinja. on 19th September 2018 Earned 15 points.
- 1797 views
- 1 answers
- 0 votes