package javaapplication12; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.logging.Level; import java.util.logging.Logger; public class JavaApplication12 { public static void main(String[] args) { Connection con = null; Statement stm = null; ResultSet rs = null; try { Class.forName("oracle.jdbc.OracleDriver"); con = DriverManager.getConnection( "jdbc:oracle:thin:@144.217.163.57:1521:XE", "hr", "inf5180"); String sql = "select country_id, country_name," + "region_name from regions join countries " + "on countries.region_id=regions.region_id"; stm = con.createStatement(); rs = stm.executeQuery(sql); String id, regionName, countryName; while (rs.next()) { id = rs.getString("country_id"); countryName = rs.getString("country_name"); regionName = rs.getString("region_name"); System.out.println(id + " - " + countryName+ " - " + regionName); } } catch (ClassNotFoundException ex) { Logger.getLogger(JavaApplication12.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(JavaApplication12.class.getName()).log(Level.SEVERE, null, ex); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { /* ignored */ } } if (stm != null) { try { stm.close(); } catch (SQLException e) { /* ignored */ } } if (con != null) { try { con.close(); } catch (SQLException e) { /* ignored */ } } } } }