新增错误提示

This commit is contained in:
高子兴 2024-07-14 18:36:20 +08:00
parent 55e61ca5fe
commit 1ce4b97fd6
2 changed files with 4 additions and 0 deletions

View File

@ -215,6 +215,9 @@ public class DatabaseService {
int count = rs.getInt(1); int count = rs.getInt(1);
if (count > 0) { if (count > 0) {
if (count>1){
throw new SQLException("Duplicate project found");
}
String updateSql = "UPDATE projects SET summary = ?, description = ?, keywords = ?, type = ?, collaborators = ?, link = ?, time = ? WHERE title = ? AND user_id = (SELECT id FROM users WHERE username = ?)"; String updateSql = "UPDATE projects SET summary = ?, description = ?, keywords = ?, type = ?, collaborators = ?, link = ?, time = ? WHERE title = ? AND user_id = (SELECT id FROM users WHERE username = ?)";
try (PreparedStatement updateStmt = conn.prepareStatement(updateSql)) { try (PreparedStatement updateStmt = conn.prepareStatement(updateSql)) {
updateStmt.setString(1, project.getSummary()); updateStmt.setString(1, project.getSummary());

View File

@ -151,6 +151,7 @@ public class ProjectBean implements Serializable {
context.addMessage("saveButton", new FacesMessage(FacesMessage.SEVERITY_INFO, "Submission Succeeded", null)); context.addMessage("saveButton", new FacesMessage(FacesMessage.SEVERITY_INFO, "Submission Succeeded", null));
loadAllKeywords(); loadAllKeywords();
} catch (SQLException e) { } catch (SQLException e) {
context.addMessage("saveButton", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Submission Failed", null));
e.printStackTrace(); e.printStackTrace();
} }
return "project"; return "project";