From 9232bdcb144bc3b94f4b825b3a4cb588078bd72d Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 17 Jan 2016 00:15:07 +0300 Subject: fix getTag --- src/main/java/com/juick/server/TagQueries.java | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/main/java/com/juick') 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); -- cgit v1.2.3