import java.sql.*; public class OjdbcExample { public static void main(String[] args) { String url = "jdbc:oracle:thin:@localhost:1521:xe"; String username = "username"; String password = "password"; try { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection connection = DriverManager.getConnection(url, username, password); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery("SELECT * FROM employees"); while (resultSet.next()) { int empId = resultSet.getInt("employee_id"); String empName = resultSet.getString("employee_name"); System.out.println("Employee ID: " + empId + ", Employee Name: " + empName); } resultSet.close(); statement.close(); connection.close(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } } <dependencies> <dependency> <groupId>com.oracle.database.jdbc</groupId> <artifactId>ojdbc10</artifactId> <version>19.3.0.0</version> </dependency> </dependencies>


上一篇:
下一篇:
切换中文