Commit 8ef637ef by Patryk Czarnik

wypisywanie również job_id

parent 0c1ef046
...@@ -17,15 +17,16 @@ public class Odczyt2 { ...@@ -17,15 +17,16 @@ public class Odczyt2 {
// - Podajemy nazwy kolumn, a nie numery. // - Podajemy nazwy kolumn, a nie numery.
public static void main(String[] args) { public static void main(String[] args) {
try(Connection c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/hr", "kurs", "abc123"); try(Connection c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/hr", "kurs", "abc123");
PreparedStatement stmt = c.prepareStatement("SELECT * FROM employees"); PreparedStatement stmt = c.prepareStatement("SELECT * FROM employees ORDER BY employee_id");
ResultSet rs = stmt.executeQuery()) { ResultSet rs = stmt.executeQuery()) {
while(rs.next()) { while(rs.next()) {
int id = rs.getInt("employee_id"); int id = rs.getInt("employee_id");
String firstName = rs.getString("first_name"); String firstName = rs.getString("first_name");
String lastName = rs.getString("last_name"); String lastName = rs.getString("last_name");
String jobId = rs.getString("job_id");
BigDecimal salary = rs.getBigDecimal("salary"); BigDecimal salary = rs.getBigDecimal("salary");
System.out.println("Pracownik nr " + id + ": " + firstName + " " + lastName + " zarabia " + salary); System.out.println("Pracownik nr " + id + ": " + firstName + " " + lastName + " (" + jobId + ") zarabia " + salary);
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment