Input
Output
import java.sql.*; public class DriverManagerExample { public static void main(String[] args) { try { // Step 1: Load the JDBC driver Class.forName("com.mysql.cj.jdbc.Driver"); // Step 2: Get a connection using DriverManager Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/testdb", "root", "password" ); // Step 3: Create a statement Statement stmt = con.createStatement(); // Step 4: Execute query ResultSet rs = stmt.executeQuery("SELECT * FROM employees"); // Step 5: Process result set while (rs.next()) { System.out.println(rs.getInt("id") + " - " + rs.getString("name")); } // Step 6: Close connection con.close(); } catch (Exception e) { e.printStackTrace(); } } }