Hackforge Academy

Category: java

JDBC

Published on 24 Feb 2026

Explanation


JDBC is used to establish a connection
between a Java application and a database.

Code:

Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/testdb",
"root","password");

Explanation


Statement interface is used to execute simple SQL queries.

Code:

Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users");

Explanation


ResultSet is used to retrieve data returned from a query.

Code:

while(rs.next()){
  System.out.println(rs.getString("name"));
}

Explanation


JDBC Driver must be loaded before
establishing connection (older versions).

Code:

Class.forName("com.mysql.cj.jdbc.Driver");

Explanation


Connection should be closed to release database resources.

Code:

con.close();

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community