Advertisement
SpudCA

java gia ton giwgo

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