diff options
author | Vitaly Takmazov | 2016-01-17 00:15:07 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-01-17 00:15:07 +0300 |
commit | 9232bdcb144bc3b94f4b825b3a4cb588078bd72d (patch) | |
tree | 61ca945d2acb9e7a00a6e14e4c39be59924675f0 /src/main | |
parent | de32a6e9e994b830fdf0768d0825559a85d19654 (diff) |
fix getTag
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/juick/server/TagQueries.java | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/main/java/com/juick/server/TagQueries.java b/src/main/java/com/juick/server/TagQueries.java index 22839ad0..f3ab480e 100644 --- a/src/main/java/com/juick/server/TagQueries.java +++ b/src/main/java/com/juick/server/TagQueries.java @@ -18,6 +18,7 @@ package com.juick.server; import com.juick.Tag; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import java.sql.Connection; @@ -52,15 +53,19 @@ public class TagQueries { } public static com.juick.Tag getTag(JdbcTemplate sql, String tag, boolean autoCreate) { - Tag ret = sql.queryForObject("SELECT tag_id,synonym_id,name FROM tags WHERE name=?", - new Object[]{tag}, (rs, rowNum) -> { - Tag ret1 = new Tag(); - ret1.TID = rs.getInt(1); - ret1.SynonymID = rs.getInt(2); - ret1.Name = rs.getString(3); - return ret1; - }); - + Tag ret = null; + try { + ret = sql.queryForObject("SELECT tag_id,synonym_id,name FROM tags WHERE name=?", + new Object[]{tag}, (rs, rowNum) -> { + Tag ret1 = new Tag(); + ret1.TID = rs.getInt(1); + ret1.SynonymID = rs.getInt(2); + ret1.Name = rs.getString(3); + return ret1; + }); + } catch (EmptyResultDataAccessException e) { + // tag not found + } if (ret == null && autoCreate) { ret = new com.juick.Tag(); ret.TID = createTag(sql, tag); |