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