diff options
author | 2016-07-11 11:28:25 +0300 | |
---|---|---|
committer | 2016-07-11 11:28:25 +0300 | |
commit | ec589172a627aee760a07e4830499cebc1943c35 (patch) | |
tree | fd1fd11fd3a63365fdb9d1a2b8d393b77d2ccfe2 /juick-core/src/main/java/com/juick/server/UserQueries.java | |
parent | 3daf98ea8ee13a75fa5819fa90f24a7e095ed769 (diff) |
backport tests (WIP)
Diffstat (limited to 'juick-core/src/main/java/com/juick/server/UserQueries.java')
-rw-r--r-- | juick-core/src/main/java/com/juick/server/UserQueries.java | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/juick-core/src/main/java/com/juick/server/UserQueries.java b/juick-core/src/main/java/com/juick/server/UserQueries.java index 13a330e5..0db929bd 100644 --- a/juick-core/src/main/java/com/juick/server/UserQueries.java +++ b/juick-core/src/main/java/com/juick/server/UserQueries.java @@ -18,6 +18,7 @@ package com.juick.server; import com.juick.User; +import org.springframework.dao.DuplicateKeyException; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; @@ -73,13 +74,17 @@ public class UserQueries { public static int createUser(JdbcTemplate sql, String username, String password) { KeyHolder holder = new GeneratedKeyHolder(); - sql.update(con -> { - PreparedStatement stmt = con.prepareStatement("INSERT INTO users(nick,passw) VALUES (?,?)", - Statement.RETURN_GENERATED_KEYS); + try { + sql.update(con -> { + PreparedStatement stmt = con.prepareStatement("INSERT INTO users(nick,passw) VALUES (?,?)", + Statement.RETURN_GENERATED_KEYS); stmt.setString(1, username); stmt.setString(2, password); return stmt; - }, holder); + }, holder); + } catch (DuplicateKeyException e) { + return -1; + } int uid = holder.getKey().intValue(); |