0% found this document useful (0 votes)
3 views1 page

JDBC in Java Notes

JDBC (Java Database Connectivity) is a standard Java API that connects Java applications to relational databases, allowing SQL queries for data operations. The connection process involves importing the java.sql package, loading the JDBC driver, creating a connection, executing SQL, and processing results. Key advantages include database independence, security with PreparedStatement, and ease of CRUD operations.

Uploaded by

Mehnaz Shoukat
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)
3 views1 page

JDBC in Java Notes

JDBC (Java Database Connectivity) is a standard Java API that connects Java applications to relational databases, allowing SQL queries for data operations. The connection process involves importing the java.sql package, loading the JDBC driver, creating a connection, executing SQL, and processing results. Key advantages include database independence, security with PreparedStatement, and ease of CRUD operations.

Uploaded by

Mehnaz Shoukat
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

JDBC (Java Database Connectivity)

Definition
JDBC (Java Database Connectivity) is a standard Java API used to connect Java applications with
relational databases such as MySQL, Oracle, and PostgreSQL. It allows programs to execute SQL
queries and retrieve or update data.

Architecture
Java Application → JDBC API → JDBC Driver → Database.

Steps to Connect to MySQL


1. Import [Link] package.
2. Load JDBC driver (modern drivers auto-load).
3. Create Connection.
4. Create Statement/PreparedStatement.
5. Execute SQL.
6. Process ResultSet.
7. Close resources.

Example Code
import [Link].*;
public class JDBCExample {
public static void main(String[] args){
String url="jdbc:mysql://localhost:3306/studentdb";
String user="root";
String pass="password";
try{
Connection con=[Link](url,user,pass);
Statement st=[Link]();
ResultSet rs=[Link]("SELECT * FROM students");
while([Link]()){
[Link]([Link]("id")+" "+[Link]("name"));
}
[Link](); [Link](); [Link]();
}catch(SQLException e){ [Link](); }
}
}
Advantages
Database independent API, secure with PreparedStatement, easy CRUD operations.

Important Interfaces
DriverManager, Connection, Statement, PreparedStatement, ResultSet.

Exam Questions
What is JDBC? List JDBC steps. Difference between Statement and PreparedStatement. What is
ResultSet?

You might also like