JDBC

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 14

JDBC

• JDBC acronym of Java Database connectivity.

• Though Sun Microsystems claims that it is not the full form. JDBC is a standard
Java API for independent database connection between a Java program and a
wide range of relational databases.

• It is present in the “java.sql” package.


Architecture of JDBC
JDBC Driver
• There are 4 types of JDBC drivers:

• JDBC-ODBC bridge driver


• Native-API driver (partially Java driver)
• Network Protocol driver (fully java driver)
• Thin driver (fully java driver)
ODBC Connectivity
Native-API driver
Network Protocol driver
Thin driver
JAVA DATABASE CONNECTIVITY
STEPS
• There are 5 steps to connect any Java application with the database
using JDBC.
• Register the Driver class
• Create connection
• Create statement
• Execute queries
• Close connection
REGISTER THE DRIVER CLASS

The forName() method of a Class is used to register the driver class.

• Class.forName("oracle.jdbc.driver.OracleDriver");

• Class.forName(“mysql.jdbc.driver.MySqlDriver");
Create the connection object
• Connection
con=DriverManager.getConnection(“jdbc:mysql://localhost:3306/student",
“root",”root");

Create the Statement object


• Statement stmt=con.createStatement();
Types of Statement
There are three types of Statement available in Statement class:-
• Statement
• PreparedStatement
PreparedStatement psmt=con.prepareStatement();
• CallableStatement
CallableStatement csmt=con.prepareCall();
Execute the query
• ResultSet rs=stmt.executeQuery("select * from emp");

Close the connection object


• con.close();

You might also like