Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication8;
- import java.sql.*;
- /**
- * @author Denis
- */
- public class JavaApplication8 {
- public static void main(String[] args) throws SQLException {
- doPrint();
- }
- public static void doPrint()
- throws SQLException {
- DriverManager.registerDriver( new oracle.jdbc.OracleDriver());
- Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "hr","hr");
- Statement stmt = conn.createStatement();
- ResultSet rset = stmt.executeQuery("(select d.DEPARTMENT_ID, d.DEPARTMENT_NAME, count(*) as num_of_emp , min(salary) as minimum_sal, max(salary) as maximum_sal\n" +
- "from departments d, employees e, jobs j\n" +
- "where d.DEPARTMENT_ID = e.department_id\n" +
- "and j.job_id = e.job_id\n" +
- "group by d.DEPARTMENT_NAME, d.DEPARTMENT_ID)\n" +
- "union\n" +
- "(select d.department_id, department_name, 0 as num_of_emp, 0 as minimum_sal, 0 as maximum_sal\n" +
- "from departments d\n" +
- "where not exists (select employee_id from employees e, jobs j\n" +
- " where j.job_id = e.job_id\n" +
- " and d.department_id = e.department_id))");
- System.out.printf( "Department ID -" + " Department Name -" + " num_of_emp -" + " minimum_sal -" + " maximum_sal" + "\n");
- while (rset.next())
- System.out.printf("%5d\t%23s\t%8d\t%8d\t%5d\n", rset.getInt("DEPARTMENT_ID"),rset.getString("DEPARTMENT_NAME"),rset.getInt("num_of_emp"),rset.getInt("minimum_sal"),rset.getInt("maximum_sal"));
- rset.close();
- stmt.close();
- conn.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement