Commit a8bf750e by Patryk Czarnik

Dodanie sterownika JDBC i druga wersja odczytu z bazy

parent abcfbbfb
......@@ -6,5 +6,6 @@
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="postgresql-42.6.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
package bazy.na_zywo;
import java.sql.*;
public class Odczyt2 {
public static void main(String[] args) {
String url = "jdbc:postgresql://localhost:5432/postgres";
try (Connection c = DriverManager.getConnection(url, "postgres", "abc123");
PreparedStatement stmt = c.prepareStatement("SELECT * FROM osoby");
ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
System.out.printf("Osoba nr %d to jest %s %s, ur. %s, zarabia %s%n",
rs.getInt("id"),
rs.getString("imie"),
rs.getString("nazwisko"),
rs.getString("data_urodzenia"),
rs.getBigDecimal("pensja"));
}
} 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