Interview Questions

Spring

Spring Handling BLOB/CLOB

In this article let's discuss about handling BLOB data in Spring JDBC.

Consider the following class which is used to insert/retrieve blob from database.

TestBlobJdbc.java

/**
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSES ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR

Spring - Execute Stored Procedure

In this article let’s discuss about how to execute stored procedures using Spring framework.

Please refer article on Spring JDBC, to know about performing JDBC operations (SQL) using Spring.

CREATE OR REPLACE PROCEDURE get_col_values(emp_names out varchar2)
   AS
   v_empnames   VARCHAR2 (4000);

   CURSOR c_emp_names
   IS
      SELECT DISTINCT emp_name FROM employees;
BEGIN
   FOR i IN c_emp_names
   LOOP
      v_empnames := v_empnames || TRIM (i.emp_name) || ',';
   END LOOP;

Spring Velocity Integration

In this article lets discuss about how to integrate velocity framework with spring.

What is Velocity?

Velocity is an open sourced template based tool mostly used for formatting in the presentation layer (similar to jsp). You can create template files, access it in your application, fill the data dynamically in the templates and return it to view layer as you do for jsps.

Spring Task Executor

In this article lets discuss about how to use Task Executor in Spring.

TaskExecutor is a simple outer layered framework to use Java's Concurrency API, the ThreadPoolExecutor.

ThreadPoolExecutor is an API used to execute set of threads and manage them efficiently.

org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor is a Spring bean to use the Java ThreadPoolExecutor in a very simple way.

Let us see an example. First we need to create the ThreadPoolTaskExecutor bean in the Spring config file.

Spring DWR Validation

This article is a sequel to article on Spring-DWR Integration

In this section, we are going to discuss about how to do validation using DWR in Spring application.

In Server side validation, generally we will submit a form to get the individual fields validated. Using DWR (which is an Ajax framework), we are going to validate each field instantly, without the need to submit the form .

We are going to use the same example as in the Spring Validation article.

Spring Validation

In this article, we will be discussing about Validation in Spring framework. In any web application, we will be often faced with a requirement to validate the fields in user interface(UI). There are basically two types of validation

1. Client side validation
2. Server side validation

Client side validation is usually done using Java Script. Server side validation is usually provided by the MVC framework. Frameworks such as Spring and Struts provide support for validation.

Now lets see, how to do simple validation using Spring.

Spring Hibernate Integration

In this article, lets discuss about integrating Hibernate with Spring framework.

Hibernate in short is an ORM tool which acts as a middle ware between Business layer and Database layer in an n-tier Java application.

Lets take up an example of Employee and Department tables, where each employee belongs to a department. We will see how to access those tables using Hibernate/Spring.

First of all, define the Employee and Department beans. Note that the Employee bean has a reference to Department.

Employee.java
 

Spring - JDBC Configuration

In this section, Let us see how to configure JDBC in Spring application.

For any Application to interact with Database, it needs a JDBC Connectivity. Using the JDBC Connection, it can perform data retrieval, insertion and update operations.

Let us see how to achieve this in Spring.

1. Create a Servlet Application Context as follows

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"

Spring - Log4j Configuration

Loggers are used to Log messages in any application. With Logger, your application has better control on what messages needs to be logged to the files. This can be achieved using the Log Levels.

Loggers have different Log Levels associated to it. For example., INFO, DEBUG, WARN, ERROR, FATAL etc. Based on the Log Levels configured, the Logger can put only those messages corresponding to Levels to the Log files. Rest of them can be ignored.

In this example, Let us see how to configure Log4j in Spring application.

Spring File Upload

In this article we will discuss about uploading files using Spring MVC applications.

In application projects, we may often be faced with requirements to upload files from UI to the web server. This can be done in spring using org.springframework.web.multipart.commons.CommonsMultipartResolver bean.

The CommonsMultipartResolver is a servlet based implementation of Jakarta Commons File Upload api. It has properties to specify maxUploadSize, maxInMemorySize and DefaultEncoding for the file to be uploaded.