package zajecia;

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

public class OdczytajEmployees2 {

	public static void main(String[] args) {
		String url = "jdbc:postgresql://localhost/hr";
		try(Connection c = DriverManager.getConnection(url, "kurs", "abc123");
			PreparedStatement stmt = c.prepareStatement("SELECT * FROM employees");
			ResultSet rs = stmt.executeQuery())
		{
			while(rs.next()) {
				String imie = rs.getString("first_name");
				String nazwisko = rs.getString("last_name");
				String job = rs.getString("job_id");
				BigDecimal salary = rs.getBigDecimal("salary");
				System.out.printf("%s %s (%s) zarabia %s\n", imie, nazwisko, job, salary);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
