package zajecia;

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

public class OdczytajEmployees1 {

	public static void main(String[] args) {
		String url = "jdbc:postgresql://localhost/hr";
		try {
			Connection c = DriverManager.getConnection(url, "kurs", "abc123");
			System.out.println("Udało się połączyć. c = " + c);
			
			Statement stmt = c.createStatement();
			ResultSet rs = stmt.executeQuery("SELECT * FROM employees");
			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);
			}
			rs.close();
			stmt.close();
			c.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

}
