package bazy.sqlite;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JOptionPane;

public class WypiszNiektorych {

	public static void main(String[] args) {
		String szukanyJob = JOptionPane.showInputDialog("Podaj nazwę stanowiska");
		// Program ma wypisać tylko pracowników z określonego stanowiska.
		
		final String sql = "SELECT * "		
				+ " FROM employees JOIN jobs USING(job_id)"
				+ " WHERE job_title = ?";
		
		try(Connection c = DriverManager.getConnection("jdbc:sqlite:hr.db");
			PreparedStatement stmt = c.prepareStatement(sql)) {
			
			stmt.setString(1, szukanyJob);
			
			try(ResultSet rs = stmt.executeQuery()) {
				while(rs.next()) {
					String firstName = rs.getString("first_name");
					String lastName = rs.getString("last_name");
					String jobTitle = rs.getString("job_title");
					int salary = rs.getInt("salary");
					System.out.printf("%s %s (%s) : %d\n", firstName, lastName, jobTitle, salary);
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

}







