Input
Output
import java.sql.*; public class OracleJDBCExample { public static void main(String[] args) { Connection con = null; Statement stmt = null; ResultSet rs = null; try { // Step 1: Load the Oracle JDBC driver Class.forName("oracle.jdbc.driver.OracleDriver"); // Step 2: Establish the connection con = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:xe", // Your Oracle DB URL "system", // Username "oracle" // Password ); // Step 3: Create a statement stmt = con.createStatement(); // Step 4: Execute query rs = stmt.executeQuery("SELECT * FROM employees"); // Step 5: Process result while (rs.next()) { System.out.println(rs.getInt("id") + " " + rs.getString("name")); } } catch (Exception e) { e.printStackTrace(); } finally { // Step 6: Close all resources try { if (rs != null) rs.close(); if (stmt != null) stmt.close(); if (con != null) con.close(); } catch (SQLException ex) { ex.printStackTrace(); } } } }