0% found this document useful (0 votes)
9 views2 pages

Database Connectivity With JDBC

JDBC (Java Database Connectivity) is the standard API for connecting Java applications to relational databases, allowing for querying, updating data, and managing transactions. Key concepts include loading the JDBC driver, establishing a connection, executing queries, processing results, and transaction management. An example code snippet demonstrates how to connect to a MySQL database and retrieve user data.

Uploaded by

someoneishere721
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)
9 views2 pages

Database Connectivity With JDBC

JDBC (Java Database Connectivity) is the standard API for connecting Java applications to relational databases, allowing for querying, updating data, and managing transactions. Key concepts include loading the JDBC driver, establishing a connection, executing queries, processing results, and transaction management. An example code snippet demonstrates how to connect to a MySQL database and retrieve user data.

Uploaded by

someoneishere721
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/ 2

Database Connectivity with JDBC

Database Connectivity with JDBC

JDBC (Java Database Connectivity) is the standard API for connecting Java applications to
relational databases. It provides methods for querying and updating data as well as managing
transactions.

Key Concepts:
- Loading the JDBC Driver: Ensure that the appropriate driver is available.
- Establishing a Connection: Use DriverManager.getConnection() with a proper URL, username, and
password.
- Executing Queries: Use Statement or PreparedStatement to execute SQL queries.
- Processing Results: Iterate over a ResultSet to access query data.
- Transaction Management: Commit or roll back transactions as needed.

Example:
--------------------------------
import java.sql.*;

public class DatabaseExample {


public static void main(String[] args) {
try {
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/mydb", "user", "password"
);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users");
while (rs.next()) {
System.out.println(rs.getString("username"));
}
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
--------------------------------

You might also like