Posted by: lrrp | January 31, 2015

JDBC and SQL Interview Questions

A list of frequently asked JDBC interview questions with answers are given below.

1) What is JDBC?


2) What is SQL?

SQL(Structured Query Language ) is a computer language for database, it includes facilities for database creation, deletion, fetching rows and modifying rows etc.It can be used to storing, manipulating and retrieving data stored in relational database.



Also, they are using different dialects, such as:

  • MS SQL Server using T-SQL,
  • Oracle using PL/SQL,

3) What does SQL allow?

  • Allows users to access data in relational database management systems.
  • Allows users to describe the data.
  • Allows users to define the data in database and manipulate that data.
  • Allows users to create and drop databases and tables.
  • Allows users to set permissions on tables, procedures, and views

4) What are the steps in executing  a SQL Query?


There are various components included in the process. These components are Query Dispatcher, Optimization Engines, Classic Query Engine and SQL Query Engine, etc. Classic query engine handles all non-SQL queries but SQL query engine won’t handle logical files.

Following is a simple diagram showing SQL Architecture:


5) What are the different SQl commands used?


SQL Commands

6) What is RDBMS?

A Relational database management system (RDBMS) is a database management system (DBMS) that is based on the relational model as introduced by E. F. Codd. RDBMS is the basis for SQL operations, and for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.

7) What is table?



| ID | NAME     | AGE | ADDRESS   | SALARY   |
|  1 | Ramesh   |  32 | Ampara    |  2000.00 |
|  2 | Nihal    |  25 | Dehiwala  |  1500.00 |
|  3 | Ranil    |  23 | Kottawa   |  2000.00 |
|  4 | Chamara  |  25 | Maharagama|  6500.00 |
|  5 | Harin    |  27 | Horana    |  8500.00 |
|  6 | Kamal    |  22 | Madampe   |  4500.00 |
|  7 | Mahinda  |  24 | Nawinna   | 10000.00 |

8) What is field?

Every table is broken up into smaller entities called fields. The fields in the CUSTOMERS table consist of ID, NAME, AGE, ADDRESS and SALARY. A field is a column in a table that is designed to maintain specific information about every record in the table.

9) What is record or row?


|  1 | Ramesh   |  32 | Ampara |  2000.00 |

A record is a horizontal entity in a table.

10) What is column?



| Ampara    |
| Dehiwala  |
| Kottawa   |
| Maharagama|
| Horana    |
| Madampe   |
| Nawinna   |

11) What is NULL value?



12) what are SQL Constraints ?



Following are commonly used constraints available in SQL:


13) what are Data Integrity ?

The following categories of the data integrity exist with each RDBMS:


14) Database Normalization


  • Ensuring data dependencies make sense.




15) Briefly Explain the First Normal Form (1NF) ?


  • Define the data items required, because they become the columns in a table. Place related data items in a table.
  • Ensure that there are no repeating groups of data.
  • Ensure that there is a primary key.

First Rule of 1NF:

You must define the data items. This means looking at the data to be stored, organizing the data into columns, defining what type of data each column contains, and finally putting related columns into their own table.

For example, you put all the columns relating to locations of meetings in the Location table, those relating to members in the MemberDetails table, and so on.

Second Rule of 1NF:

The next step is ensuring that there are no repeating groups of data. Consider we have the following table.

       ID   INT              NOT NULL,
       NAME VARCHAR (20)     NOT NULL,
       AGE  INT              NOT NULL,
       ADDRESS  CHAR (25),
       ORDERS   VARCHAR(155)

So if we populate this table for a single customer having multiple orders, then it would be something as follows:


But as per 1NF, we need to ensure that there are no repeating groups of data. So let us break above table into two parts and join them using a key as follows:


       ID   INT              NOT NULL,
       NAME VARCHAR (20)     NOT NULL,
       AGE  INT              NOT NULL,
       ADDRESS  CHAR (25),

This table would have the following record:

1NF customer

ORDERS table:

       ID   INT              NOT NULL,
       ORDERS   VARCHAR(155),

This table would have the following records

1NF order

Third Rule of 1NF:

The final rule of the first normal form, create a primary key for each table which we have already created.

16) Briefly Explain the Database – Second Normal Form (2NF)?

Second normal form states that it should meet all the rules for 1NF and there must be no partial dependencies of any of the columns on the primary key:

Consider a customer-order relation and you want to store customer ID, customer name, order ID and order detail, and date of purchase:

       CUST_ID    INT              NOT NULL,
       CUST_NAME VARCHAR (20)      NOT NULL,
       ORDER_ID   INT              NOT NULL,

This table is in first normal form, in that it obeys all the rules of first normal form. In this table, the primary key consists of CUST_ID and ORDER_ID. Combined, they are unique assuming same customer would hardly order same thing.

However, the table is not in second normal form because there are partial dependencies of primary keys and columns. CUST_NAME is dependent on CUST_ID, and there’s no real link between a customer’s name and what he purchased. Order detail and purchase date are also dependent on ORDER_ID, but they are not dependent on CUST_ID, because there’s no link between a CUST_ID and an ORDER_DETAIL or their SALE_DATE.

To make this table comply with second normal form, you need to separate the columns into three tables.

First, create a table to store the customer details as follows:

       CUST_ID    INT              NOT NULL,
       CUST_NAME VARCHAR (20)      NOT NULL,

Next, create a table to store details of each order:

       ORDER_ID   INT              NOT NULL,

Finally, create a third table storing just CUST_ID and ORDER_ID to keep track of all the orders for a customer:


17)  Briefly Explain the Database – Third Normal Form (3NF)?

A table is in third normal form when the following conditions are met:

  • It is in second normal form.
  • All non-primary fields are dependent on the primary key.

The dependency of non-primary fields is between the data. For example, in the below table, street name, city, and state are unbreakably bound to the zip code.

       CUST_ID       INT              NOT NULL,
       CUST_NAME     VARCHAR (20)      NOT NULL,
       DOB           DATE,
       STREET        VARCHAR(200),
       CITY          VARCHAR(100),
       STATE         VARCHAR(100),
       ZIP           VARCHAR(12),
       EMAIL_ID      VARCHAR(256),

The dependency between zip code and address is called a transitive dependency. To comply with third normal form, all you need to do is move the Street, City, and State fields into their own table, which you can call the Zip Code table:

       ZIP           VARCHAR(12),
       STREET        VARCHAR(200),
       CITY          VARCHAR(100),
       STATE         VARCHAR(100),

Next, alter the CUSTOMERS table as follows:

       CUST_ID       INT              NOT NULL,
       CUST_NAME     VARCHAR (20)      NOT NULL,
       DOB           DATE,
       ZIP           VARCHAR(12),
       EMAIL_ID      VARCHAR(256),

The advantages of removing transitive dependencies are mainly twofold. First, the amount of data duplication is reduced and therefore your database becomes smaller.

The second advantage is data integrity. When duplicated data changes, there’s a big risk of updating only some of the data, especially if it’s spread out in a number of different places in the database. For example, if address and zip code data were stored in three or four different tables, then any changes in zip codes would need to ripple out to every record in those three or four tables.

Leave a Reply


You are commenting using your account. Log Out / Change )

Twitter picture


Facebook photo


Google+ photo


Connecting to %s


%d bloggers like this: