Commit cdb57456 by Patryk Czarnik

Odczyt employeesów

parent a8b620f5
...@@ -5,7 +5,7 @@ import java.sql.*; ...@@ -5,7 +5,7 @@ import java.sql.*;
public class Odczyt2 { public class Odczyt2 {
public static void main(String[] args) { public static void main(String[] args) {
String url = "jdbc:postgresql://localhost:5432/postgres"; String url = "jdbc:postgresql://localhost:5432/postgres";
try (Connection c = DriverManager.getConnection(url, "postgres", "abc123"); try(Connection c = DriverManager.getConnection(url, "postgres", "abc123");
PreparedStatement stmt = c.prepareStatement("SELECT * FROM osoby"); PreparedStatement stmt = c.prepareStatement("SELECT * FROM osoby");
ResultSet rs = stmt.executeQuery()) { ResultSet rs = stmt.executeQuery()) {
while (rs.next()) { while (rs.next()) {
......
package bazy.na_zywo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class OdczytajWszystkich {
public static void main(String[] args) {
String url = "jdbc:postgresql://localhost:5432/hr";
try(Connection c = DriverManager.getConnection(url, "kurs", "abc123");
PreparedStatement stmt = c.prepareStatement("SELECT * FROM employees");
ResultSet rs = stmt.executeQuery()) {
while(rs.next()) {
System.out.printf("Pracownik nr %d, %s %s (%s) zarabia %s%n",
rs.getInt("employee_id"),
rs.getString("first_name"),
rs.getString("last_name"),
rs.getString("hire_date"),
rs.getBigDecimal("salary"));
}
} catch(SQLException e) {
throw new RuntimeException(e);
}
}
}
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