0% found this document useful (0 votes)
132 views11 pages

5.JDBC Imp Questions

Here is Jdbc important MCQ

Uploaded by

joshiprakash3030
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views11 pages

5.JDBC Imp Questions

Here is Jdbc important MCQ

Uploaded by

joshiprakash3030
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Java JDBC Interview Questions Pdf

Question: 1

What is JDBC?
It is an API. The latest version of JDBC API is (3.0)

The JDBC 3.0 API is divided into two packages.

java.sql

javax.sql

Both packages are included in the J2SE and J2EE platforms.

Advantages:

The JDBC API can be used to interact with multiple data sources in a distributed heterogeneous
environment.

It can connect to any of the database from java language.

It can switch over to any backend database without changing java code or by minute changes.

Question: 2

What are the two major components of JDBC?


One implementation interface fir database manufacturers, the other implementation interface for
application and applet writers.

Question: 3

What are the types of JDBC driver models?


There are two JDBC driver models and they are

Two tier model: In this method, Java applications together interact directly with the database.

A JDBC driver is required to communicate with the particular database management system that
is being accessed.
SQL statements are sent to the database and the results are given to user.

This model is referred to as client/server configuration where user is the client and the machine
that has the database is called as the server.

Three tier model: A middle tier is introduced in this model. The function of this model are

Collection of SQL statements from the client and handing it over to the database,

Receiving results from database to the client and

Maintaining control over accessing and updating of the above.

Question: 4

Which methods and classes are used for connection


pooling?
JDBC provides an interface, which must be implemented by a JDBC driver supporting
connection pooling.

This interface is called ConnectionPoolDataSource.

Most existing JDBC drivers (DataSource instances) implement this interface. It provides the
following methods for obtaining PooledConnections:

PooledConnection get PooledConnection() throws SQLException;

PooledConnection get PooledConnection (String user, String password) throws SQLException;

Such connections can be closed by issuing connection.close(), but it’s only a logical closing, not
physical.

Physically, no connection is closed, it’s just returned to the pool.

Question: 5

Why most of the classes given in JDBC API are


interfaces?
Abstract class forces all sub classes to implement common method whichever are required
implementations.

Only abstract method and class can do this job.

That’s why most part of the JDBC API is a formation of interfaces.


Java JDBC Interview Questions and Answers Pdf
Question: 1

What is JDBC Driver Interface?


The JDBC Driver Interface provides vendor specific implementations of the abstract classes
provided by the JDBC API.

Each Vendor’s driver must provide implementations of the java.sql.Connection, Statement,


PreparedStatement, CallableStatement, ResultSet and driver.

Question: 2

What packages are used in JDBC?


There are 8 packages:

java.sql.Driver,

Connection,

Statement,

PreparedStatement,

CallableStatement,

ResultSet,

ResultSetMetaData,

DatabaseMetaData.

Question: 3

What are the types of statements in JDBC?


Statement – to be used createStatement() method for executing single SQL statement.

PreparedStatement – To be used preparedStatement() method for executing same SQL


statement over and over.
CallableStatement – To be used prepareCall() method for multiple SQL statements over and
over.

Question: 4

What is the difference between JDBC 1.0 and JDBC


2.0?
The JDBC 2.0 API includes many new features in the java.sql package as well as the new
Standard Extension package, javax.sql. This new JDBC API moves Java applications into the
world of heavy duty database computing.

The new JDBC Standard Extension API, an integral part of Enterprise Java Beans (EJB)
technology, allows you to write distributed transactions that use connection pooling, and it also
makes it possible to connect to virtually any tabular data source, including files and spread
sheets.

The JDBC 2.0 API includes many new features like

Scrollable result sets

Batch Updates

Connection Pooling

Distributed transactions

set autocomit()

Question: 5

What is JDBC?
JDBC is a set of Java API for executing SQL statements.

This API contains of a set of classes and interfaces to enable programs to write pure Java
Database applications.

JDBC is a layer of abstraction that allows users to choose between database. It allows you to
change to a different engine and to write to a Single API.

JDBC allows you to write database applications in Java without having to concern yourself with
the underlying details of a particular database.
JDBC standards for Java Database Connectivity. It is a specification given by Sun Microsystems
and standards followed by X/Open SAG (SQL Access Group) CLI (Call Level Interface) to
interact with the DB.

Question: 6

How many JDBC Drivers are there?


There are four types of JDBC drivers.

JDBC – ODBC Bridge Driver (Type – 1 driver)

Native API Partly Java Driver (Type – 2 driver)

Net Protocol Pure Java Driver (Type – 3 driver)

Native Protocol Pure Java Driver (Type – 4 driver)

Question: 7

What is the difference between JDBC and ODBC?


ODBC is for Microsoft and JDBC is for Java applications.

ODBC can’t be directly used with Java because it uses a C interface.

ODBC makes use of pointers which have been removed totally from Java.

ODBC mixes simple and advanced features together and has complex options for simple queries.
But JDBC is designed to keep things simple while allowing advanced capabilities when required.

ODBC requires manual installation of the ODBC driver manager and driver on all client
machines. JDBC drivers are written in Java and JDBC code is automatically installable, secure,
and portable on all platforms.

JDBC API is a natural Java interface and is built on ODBC. JDBC retains some of the basic
features of ODBC.

Question: 8

What are the different types of exceptions in JDBC?


batchUpdate Exception
Data Truncation

SQL Exception

SQL Warning

Question: 9

What are the steps for connecting to the database


using JDBC?
Using DriverManager:

Load the driver class using class.forName(driverclass) and Class.forName() loads the driver
class and passes the control to DriverManager class.

DriverManager.getConnection() creates the connection to the database.

Using DataSource:

DataSource is used instead of DriverManager in Distributed Environment with the help of JNDI.

Use JNDI to lookup the DataSource from Naming service server.

DataSource.getConnection method will return Connection object to the database.

Question: 10

What are the steps involved in establishing a


connection?
This involves two steps:

loading the drivers and

making the connection


Java JDBC Interview Questions for Experienced Pdf
Question: 1

What are the common tasks of JDBC?


Create an instance of a JDBC driver or load JDBC drivers through jdbc.drivers

Register a driver

Specify a database

Open a database connection

Submit a query

Receive results

Question: 2

Name the new features added in JDBC 4.0?


The major features introduced in JDBC 4.0 are

Auto loading by JDBC driver class

Enhanced Connection management

RowId SQL enabled

Dataset implemented by SQL by using Annotations

Enhancements of SQL exception handling

Supporting SQL XML files

Question: 3

What type of driver did you use in project?


JDBC – ODBC Bridge driver (is a driver that uses native(C language) libraries and makes calls
to an existing ODBC driver to access a database engine).
Question: 4

Describe how the JDBC application works?


A JDBC application may be divided into two layers.

Driver layer

Application layer

The Application layer begins after putting a request to the Driver Manager for the connection.

An appropriate driver is chosen and used for establishing the connection.

This connection is linked to the application layer.

The application needs the connection for creating the Statement kind of objects by which the
results are obtained.

Question: 5

How JDBC API is common to all the database and


also to all drivers?
JDBC API uses Factory method and Abstract Factory Design pattern implementations to make
API common to all the Databases and Drivers.

In fact most of the classes available in JDBC API are interfaces, where Driver vendors must
provide implementation for the above said interfaces.
Java JDBC Interview Questions for Freshers Pdf
Question: 6

Why PreparedStatements are faser?


PreparedStatements execution is faster than direct execution for statements executed more than
three or four times because the statements is compiled only once.

Prepared statements and JDBC driver are linked with each other.

We can bind drivers with columns by triggering the query into the database.

When we execute Connection prepareStatement(), all the columns bindings take place, in order
to reduce the time.

Question: 7

Write the syntax of URL to get connection?


jdbc:<subprotocol>:<subname>

jdbc: is a protocol. This is only allowed protocol in JDBC.

<subprotocol>: The subprotocol is used to identify a database driver, or the name of the database
connectivity mechanism, chosen by the database driver providers.

<subname>: The syntax of the subname is driver specific. The driver may chosen any syntax
appropriate for its implementation.

Question: 8

Can java objects be stored in database?


Yes. We can store java objects. By using setObjects(), setBlob() and setClob() methods in
PreparedStatement.

Question: 9

What causes No suitable driver error?


No suitable driver is occurs during a call to the DriverManager.getConnection method, may be
any of the following reasons.

Due to failing to load the appropriate JDBC drivers before calling the getConnection method.

It can be specifying an invalid JDBC URL, one that is not recognized by JDBC driver.

This error can occur if one or more the shared libraries needed by the bridge cannot be loaded.

Question: 10

How to set NULL values in JDBC


PreparedStatement?
We can use PreparedStatement setNull() method to bind the null variable to a parameter.

The setNull method takes index and SQL Types as arguments, for example

ps.setNull(10, java.sql.Types.INTEGER);

You might also like