Advertisement
Guest User

gia ton mario

a guest
Mar 22nd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. package javaapplication8;
  2. import java.sql.*;
  3. /**
  4.  * @author Denis
  5.  */
  6. public class JavaApplication8 {
  7.  
  8.     public static void main(String[] args)  throws SQLException {
  9.         doPrint();
  10.     }
  11.      public static void doPrint()  
  12.         throws SQLException {
  13.         DriverManager.registerDriver( new oracle.jdbc.OracleDriver());
  14.         Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "hr","hr");
  15.        
  16.         Statement stmt = conn.createStatement();
  17.         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" +
  18.         "from departments d, employees e, jobs j\n" +
  19.         "where d.DEPARTMENT_ID = e.department_id\n" +
  20.         "and j.job_id = e.job_id\n" +
  21.         "group by d.DEPARTMENT_NAME, d.DEPARTMENT_ID)\n" +
  22.         "union\n" +
  23.         "(select d.department_id, department_name,  0 as num_of_emp, 0 as minimum_sal, 0 as maximum_sal\n" +
  24.         "from departments d\n" +
  25.         "where not exists (select employee_id from employees e, jobs j\n" +
  26.         "  where j.job_id = e.job_id\n" +
  27.         "  and d.department_id = e.department_id))");
  28.        
  29.         System.out.printf( "Department ID -" + " Department Name -" + " num_of_emp -" + " minimum_sal -" + " maximum_sal" + "\n");
  30.         while (rset.next())
  31.             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"));
  32.         rset.close();
  33.         stmt.close();
  34.         conn.close();
  35.      }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement