Java Basic Tutorial
Java Advance Tutorial
JDBC (Java Database Connectivity) is an API (Application Programming Interface) that allows Java applications to interact with databases. It provides methods to connect, execute queries, retrieve data, and manipulate databases using Java code.
Java applications need a way to communicate with databases like MySQL, PostgreSQL, Oracle, and SQL Server. JDBC acts as a bridge between Java programs and relational databases.
To interact with a database using JDBC, follow these 5 steps:
Use the DriverManager.getConnection()
method.
A Statement object is used to execute SQL queries.
Use executeQuery()
for SELECT statements and executeUpdate()
for INSERT, UPDATE, DELETE.
Retrieve data from the ResultSet
object.
Always close database connections to free up resources.