Hackforge Academy

Category: React • Beginner

Published on 24 Feb 2026

Explanation

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

Code Example

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

Explanation

#white-Statement interface is used to execute simple SQL queries.

Code Example

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

Explanation

#white-ResultSet is used to retrieve data returned from a query.

Code Example

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

Explanation

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

Code Example

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

Explanation

#white-Connection should be closed to release database resources.

Code Example

con.close();

Want structured learning with real projects?

Join our Weekend Live Workshop and become job-ready faster.