Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.java.programmer Subject: Re: Where to put the return Date: Tue, 15 Aug 2017 08:12:00 +0200 Organization: Decebal Computing Lines: 42 Message-ID: <87y3qlnyvj.fsf@munus.decebal.nl> References: <87zib6zeup.fsf@munus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="72fb8bea0235c6b94245dccb186de60d"; logging-data="16731"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+pZjWZbVZTqi0/k8pYBEH+OUjLXqblc2k=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-Homepage: http://www.decebal.nl/ Cancel-Lock: sha1:djo6SSiWMtJTK70Y+KrlZmadXus= sha1:odov3e1mE29aF/SBTux2qRfsfxU= Xref: csiph.com comp.lang.java.programmer:37229 Robert Klemme writes: > Btw. I'd rather throw in catch than return a special value. That is > cleaner and does not break if the special value actually occurs in the > database. I agree. But that is what the call to fatalError does: it cleans up resources and exits the program. But I changed that to just let the SQLException fire: private static String getOldestUsed() throws SQLException { String oldestUsed = ""; try (SQLResultSet rsOldest = sqlite3Conn.executeQuery(OLDEST_USED)) { if (rsOldest.next()) { oldestUsed = rsOldest.getString("used"); } } return oldestUsed; } > And another remark: we do not see the SQL but in this case I would make > sure that OLDEST_USED actually returns exactly one column and access > that via index instead of name. IIRC this tends to be slightly quicker. > But it may be just an old habit of mine. One of the things I do is make sure you cannot use index. I find that a very bad habit. Also when you give the wrong query, but it gives one column back, you have a hard to find bug. The SQL used: SELECT used FROM usedProverbs LIMIT 1 I defined usedProverbs as a sorted view (on proverbs), that is why there is no SORT BY. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof