0% found this document useful (0 votes)
4 views3 pages

Adv Java Notes-Pr

The document explains Java Database Connectivity (JDBC), a Java API for connecting to databases using various drivers. It outlines the JDBC architecture, which consists of the JDBC API and JDBC Driver API, and describes common components like DriverManager, Connection, and ResultSet. Additionally, it details the JDBC process for establishing database connectivity and the life cycle stages of a thread in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Adv Java Notes-Pr

The document explains Java Database Connectivity (JDBC), a Java API for connecting to databases using various drivers. It outlines the JDBC architecture, which consists of the JDBC API and JDBC Driver API, and describes common components like DriverManager, Connection, and ResultSet. Additionally, it details the JDBC process for establishing database connectivity and the life cycle stages of a thread in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Java interacts with database using a common database application programming interface

called as JDBC (Java Database Connectivity). JDBC is a Java API to connect and execute the
query with the database. JDBC API uses JDBC drivers (JDBC-ODBC Bridge Driver, Native
Driver etc.) to connect with the database.

JDBC ARCHITECTURE
The JDBC API supports both two-tier and three-tier processing models for database access
but in general, JDBC Architecture consists of two layers:

1. JDBC API: This provides the application-to-JDBC Manager connection.

2. JDBC Driver API: This supports the JDBC Manager-to-Driver Connection.

The JDBC API uses a driver manager and database-specific drivers to provide transparent
connectivity to heterogeneous databases.

Common JDBC Components:

1. DriverManager class manages a list of database drivers. Matches connection


requests from the java application with the proper database driver using
communication sub protocol.
2. Driver Interface handles the communications with the database server. We will
interact directly with Driver objects very rarely, instead, we use DriverManager
objects, which manages objects of this type. It also abstracts the details associated
with working with Driver objects.
3. Connection Interface with all methods for contacting a database. The connection
object represents communication context, all communication with database is
through connection object only.
4. Statement we use objects created from this interface to submit the SQL statements
to the database. Some derived interfaces accept parameters in addition to executing
stored procedures.
5. ResultSet Objects hold data retrieved from a database after we execute an SOL query
using Statement objects. It acts as an iterator to allow us to move through its data.
6. SQLException class handles any errors that occur in a database application.
JDBC PROCESS

Steps to create connectivity to the database:

Step 1: Load the driver and establish a database connection to the MS-Access/
PostgreSQL/mysql server.

Step 2: Create an instance of the Statement object.

Step 3: Execute a statement to get a ResultSet object.

Step 4: Process the ResultSet object.

Step 5: Close the database connection.

1. Load & Register Driver


= [Link] (“Driver Name”);
2. Create connection
=connection con = [Link](“url”,”username”,”password”);
3. Create statement
=PreparedStatement ps = [Link](“Sql query”);
4. Execute SQL Statement
=[Link]();
5. Process the result
6. Close the connection
=[Link]();

LIFE CYCLE OF THREAD

A thread goes through various stages in its life cycle. For example, a thread is born, started,
runs, and then dies. This is also known as life cycle of a thread. The life cycle of the thread in
java is controlled by JVM.

1. New: A new thread begins its life cycle in the new state. It remains in this state until the
program starts the thread. It is also referred to as a born thread. The thread is in new state if
you create an instance of Thread class but before the invocation of start() method.

2. Runnable: The thread is in runnable state after invocation of start() method, but the
thread scheduler has not selected it to be the running thread.

3. Running: The thread is in running state ifthe thread scheduler has selected it.

4. Non-Runnable (Blocked): This is the state when the thread is still alive, but is currently
not eligible to run.

5. Terminated: A thread is in terminated or dead state when its run() method exits.

You might also like