Guest User

Untitled

a guest
Nov 15th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. package com.indra;
  2. /*
  3. Elaborar un programa JDBC que permita mostrar los datos de unos empleados determinados. Utilize al menos un JOIN.
  4. */
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.PreparedStatement;
  8. import java.sql.ResultSet;
  9. import java.sql.SQLException;
  10.  
  11. public class App {
  12. public static void main(String[] args) throws SQLException {
  13. String zEmployees = "SELECT DISTINCT first_name FROM employees.employees WHERE first_name LIKE 'z%'";
  14. String empAfter1960 = "SELECT DISTINCT A.first_name, B.dept_no FROM employees.employees A INNER JOIN employees.dept_manager B WHERE A.birth_date > '1960-01-01' LIMIT 10;";
  15. try(Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employees?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC", "escofet", "Escofet_123")) {
  16. try(PreparedStatement pstmt1 = con.prepareStatement(zEmployees); ResultSet rs1 = pstmt1.executeQuery()) {
  17. while(rs1.next()) {
  18. System.out.println(rs1.getString("first_name"));
  19. }
  20. }
  21. try(PreparedStatement pstmt2 = con.prepareStatement(empAfter1960);ResultSet rs2 = pstmt2.executeQuery()) {
  22. while(rs2.next()) {
  23. System.out.println(rs2.getString("first_name") + " - " + rs2.getString("dept_no"));
  24. }
  25. }
  26. }
  27. }
  28. }
Add Comment
Please, Sign In to add comment