import java.sql.*;
public class OJDBCExample {
public static void main(String[] args) {
String url = "jdbc:oracle:thin:@localhost:1521:XE";
String username = "your_username";
String password = "your_password";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try (Connection con = DriverManager.getConnection(url, username, password)) {
String sql = "SELECT * FROM employees";
try (Statement stmt = con.createStatement()) {
try (ResultSet rs = stmt.executeQuery(sql)) {
while (rs.next()) {
int empId = rs.getInt("employee_id");
String empName = rs.getString("employee_name");
System.out.println("Employee ID: " + empId + ", Employee Name: " + empName);
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}