Skip to content

Latest commit

 

History

History
31 lines (30 loc) · 743 Bytes

File metadata and controls

31 lines (30 loc) · 743 Bytes

Vous vous souvenez de JDBC ?

try {
    conn = this.datasource.getConnection();
    stmt = conn.prepareStatement("select ID, FNAME, LNAME from person where LNAME = ?");
    stmt.setString(1, lname);
    ResultSet rs = stmt.executeQuery();
    while (rs.next()) {
        p = new Person();
        p.setId(rs.getInt("ID"));
        p.setFirstName(rs.getString("FNAME"))
        p.setLastName(rs.getString("LNAME"));
    }
} catch (SQLException e) {
    LOGGER.error(e);
} finally {
    try {
        if (stmt != null)
            stmt.close();
    } catch (SQLException e) {
        LOGGER.warn(e);
    }
    try {
        if (conn != null)
            conn.close();
    } catch (SQLException e) {
        LOGGER.warn(e);
    }
}