Commit 9c199796 by Patryk Czarnik

PolaczPostgres2 (VSP)

parent 73255e46
package bazy.a_poczatek;
import java.math.BigDecimal;
import java.sql.*;
public class PolaczPostgres2 {
public static void main(String[] args) {
try (Connection c = DriverManager.getConnection(
"jdbc:postgresql://vps497901.ovh.net/hr",
"kurs",
"vps497901_abc123");
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();
}
}
}
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