Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.indra;
- /*
- Elaborar un programa JDBC que permita mostrar los datos de unos empleados determinados. Utilize al menos un JOIN.
- */
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class App {
- public static void main(String[] args) throws SQLException {
- String zEmployees = "SELECT DISTINCT first_name FROM employees.employees WHERE first_name LIKE 'z%'";
- 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;";
- try(Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employees?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC", "escofet", "Escofet_123")) {
- try(PreparedStatement pstmt1 = con.prepareStatement(zEmployees); ResultSet rs1 = pstmt1.executeQuery()) {
- while(rs1.next()) {
- System.out.println(rs1.getString("first_name"));
- }
- }
- try(PreparedStatement pstmt2 = con.prepareStatement(empAfter1960);ResultSet rs2 = pstmt2.executeQuery()) {
- while(rs2.next()) {
- System.out.println(rs2.getString("first_name") + " - " + rs2.getString("dept_no"));
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment