1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| public void record() throws SQLException, NamingException, MyException, UnsupportedEncodingException {
recordMainFields();
categories.record();
}
private void recordMainFields() throws SQLException, NamingException, MyException, UnsupportedEncodingException {
url = url.replaceAll("/", "").toLowerCase();
calculPagerank();
String query = "INSERT INTO site (titre, url, description, id_user, pagerank, protocol) VALUES (?,?,?,?, ?,?) RETURNING id";
try (PreparedStatement prepare = getConn().prepareStatement(query)) {
prepare.setString(1, encod(titre));
prepare.setString(2, encod(url));
prepare.setString(3, encod(description));
prepare.setLong(4, user.id);
prepare.setInt(5, pagerank);
prepare.setInt(6, protocol);
try (ResultSet result = prepare.executeQuery()) {
if (result.next()) {
id = result.getLong("id");
} else {
throw new MyException("Erreur lors de l'enregistrement du site.<br/>");
}
}
}
} |
Partager