0% found this document useful (0 votes)
35 views

Why Should We Use JDBC: Class - Forname

JDBC (Java Database Connectivity) is a Java API that allows Java programs to connect to and execute queries on any relational database. It uses JDBC drivers to connect to databases and provides methods to save, update, delete, and fetch data. There are four types of JDBC drivers: JDBC-ODBC bridge driver, native driver, network protocol driver, and thin driver. JDBC was created as Java has its own database API since ODBC uses C language drivers which are platform dependent and less secure.

Uploaded by

Maithili
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)
35 views

Why Should We Use JDBC: Class - Forname

JDBC (Java Database Connectivity) is a Java API that allows Java programs to connect to and execute queries on any relational database. It uses JDBC drivers to connect to databases and provides methods to save, update, delete, and fetch data. There are four types of JDBC drivers: JDBC-ODBC bridge driver, native driver, network protocol driver, and thin driver. JDBC was created as Java has its own database API since ODBC uses C language drivers which are platform dependent and less secure.

Uploaded by

Maithili
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
You are on page 1/ 3

JDBC stands for Java Database Connectivity.

JDBC is a Java API to connect and execute the


query with the database. We can use JDBC API to access tabular data stored in any relational
database. By the help of JDBC API, we can save, update, delete and fetch data from the
database. It is a part of JavaSE (Java Standard Edition). JDBC API uses JDBC drivers to
connect with the database. There are four types of JDBC drivers:

 JDBC-ODBC Bridge Driver,


 Native Driver,
 Network Protocol Driver, and
 Thin Driver

Why Should We Use JDBC

Before JDBC, ODBC API was the database API to connect and execute the query with the
database. But, ODBC API uses ODBC driver which is written in C language (i.e. platform
dependent and unsecured). That is why Java has defined its own API (JDBC API) that uses
JDBC drivers (written in Java language).

We can use JDBC API to handle database using Java program and can perform the following
activities:

1. Connect to the database


2. Execute queries and update statements to the database
3. Retrieve the result received from the database.

Class.forName()-

A call to forName("X") causes the class named X to be initialized.


where initialization involves code in static block to be executed.
So basically, you initialize the Driver class, and in turn the class registers itself with the
java.sql.DriverManager per the JDBC specification.
JDBC Driver is a software component that enables java application to interact with the database.
There are 4 types of JDBC drivers:

1. JDBC-ODBC bridge driver


2. Native-API driver (partially java driver)
3. Network Protocol driver (fully java driver)
4. Thin driver (fully java driver)

1) JDBC-ODBC bridge driver

The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The JDBC-ODBC
bridge driver converts JDBC method calls into the ODBC function calls. This is now
discouraged because of thin driver.

Connection interface

A Connection is the session between java application and database. The Connection interface is a
factory of Statement, PreparedStatement, and DatabaseMetaData i.e. object of Connection can be
used to get the object of Statement and DatabaseMetaData. The Connection interface provide
many methods for transaction management like commit(), rollback() etc

DriverManager class
The DriverManager class acts as an interface between user and drivers. It keeps track of the drivers that
are available and handles establishing a connection between a database and the appropriate driver. The
DriverManager class maintains a list of Driver classes that have registered themselves by calling the
method DriverManager.registerDriver().

import java.sql.*;
class Test1{
public static void main(String ar[]){
try{
String url="jdbc:odbc:mydsn";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection(url);
Statement st=c.createStatement();
ResultSet rs=st.executeQuery("select * from Stud");

while(rs.next()){
System.out.println(rs.getInt(1)+":"+rs.getString(2));
}

}catch(Exception ee){System.out.println(ee);}

}}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy