package bazy.a_poczatek;

import java.math.BigDecimal;
import java.sql.*;

public class PolaczSQLite {

    public static void main(String[] args) {
        try (Connection c = DriverManager.getConnection("jdbc:sqlite:hr.db");
             PreparedStatement stmt = c.prepareStatement("SELECT * FROM employees");
             ResultSet rs = stmt.executeQuery()) {

            while (rs.next()) {
                // odczyt wg numerów kolumn, numeracja od 1
                int id = rs.getInt(1);
                String firstName = rs.getString(2);
                String lastName = rs.getString(3);

                // odczyt wg nazw kolumn:
                String job = rs.getString("job_id");
                BigDecimal salary = rs.getBigDecimal("salary");

                System.out.printf("%d: %s %s (%s) zarabia %s\n", id, firstName, lastName, job, salary);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
