package bazy.sqlite;

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

public class Odczyt2 {

	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()) {
				// W tej wersji dane z poszczególnych pól odczytujemy wg nazwy kolumny
				String firstName = rs.getString("first_name");
				String lastName = rs.getString("last_name");
				int salary = rs.getInt("salary");
				System.out.println(firstName + " " + lastName + " zarabia " + salary);
			}

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
