org.sfm.jdbc.README.md Maven / Gradle / Ivy
JdbcMapper
---------
```java
public class MyDao {
private final JdbcMapper mapper =
JdbcMapperFactory.newInstance().newMapper(MyObject.class);
public void printAllLambda(Writer writer, Connection conn) throws SQLException {
try (PreparedStatement ps =
conn.prepareStatement("select id, email, my_property from MyTable")) {
try (ResultSet rs = ps.executeQuery()){
mapper.forEach(rs, (o) -> writer.append(o.toString()).append("\n"));
}
}
}
public void printAll(Writer writer, Connection conn) throws SQLException {
try (PreparedStatement ps =
conn.prepareStatement("select id, email, my_property from MyTable")) {
try (ResultSet rs = ps.executeQuery()){
mapper.forEach(rs, new RowHandler{
public void handle(MyObject o) throws IOException {
writer.append(o.toString()).append("\n"));
}
});
}
}
}
}
```