<?xml version="1.0"?>
<rss version="2.0">
<channel>

  
  
<title>Question of the Day - Responses</title>
<link>http://enigmastation.com:80/pebble/qotd/</link>
<description>Interesting questions and answers on Java</description>
<language>en</language>
<managingEditor>Joseph Ottinger</managingEditor>
<lastBuildDate>Wed, 03 Dec 2008 19:32:17 GMT</lastBuildDate>
  

  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <item>
    <title>Re: How do I get a stack trace in a String?</title>
    <link>http://enigmastation.com:80/pebble/qotd/2008/12/03/1228314720000.html#comment1228332737487</link>
    <description>
      Hi there,&lt;br /&gt;
&lt;br /&gt;
Just a minor correction.&amp;nbsp; &amp;quot;sw&amp;quot; needs to be passed to the PrintWriter constructor.&lt;br /&gt;
&lt;br /&gt;
Thanks for putting up this blog!
    </description>
    <author>Ever</author>
    <comments>http://enigmastation.com:80/pebble/qotd/2008/12/03/1228314720000.html#comments</comments>
    <guid isPermaLink="true">http://enigmastation.com:80/pebble/qotd/2008/12/03/1228314720000.html#comment1228332737487</guid>
    <pubDate>Wed, 03 Dec 2008 19:32:17 GMT</pubDate>
  </item>
  
  <item>
    <title>Re: Horrible JDBC Code and What&#039;s Wrong With It</title>
    <link>http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comment1226625709553</link>
    <description>
      I can agree with not wanting to introduce dependencies, but this is the way to do non-ORM database access in Java at the moment. It&#039;s not so ok to write twenty lines of raw JDBC, if you can do it in a couple of lines with JdbcTemplate.&lt;br /&gt;
&lt;br /&gt;
Even if you don&#039;t want to use Spring (I can definitely see why one wouldn&#039;t), you can write your own JdbcTemplate analogue -- it may not be totally trivial, but it&#039;s not very complicated either and one that handles 80% of the functionality can probably be done in 200 lines of code (wild guess). Maybe you could even copy some of the code from Spring, I think the license allows that.
    </description>
    <author>Erkki Lindpere</author>
    <comments>http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comments</comments>
    <guid isPermaLink="true">http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comment1226625709553</guid>
    <pubDate>Fri, 14 Nov 2008 01:21:49 GMT</pubDate>
  </item>
  
  <item>
    <title>Re: Horrible JDBC Code and What&#039;s Wrong With It</title>
    <link>http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comment1226605626924</link>
    <description>
      Also, storing pin codes in plaintext is not a good idea.
    </description>
    <author>Keccs</author>
    <comments>http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comments</comments>
    <guid isPermaLink="true">http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comment1226605626924</guid>
    <pubDate>Thu, 13 Nov 2008 19:47:06 GMT</pubDate>
  </item>
  
  <item>
    <title>Re: Horrible JDBC Code and What&#039;s Wrong With It</title>
    <link>http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comment1226590261940</link>
    <description>
      JdbcTemplate, JdbcTemplate, JdbcTemplate
    </description>
    <author>Anonymous</author>
    <comments>http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comments</comments>
    <guid isPermaLink="true">http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comment1226590261940</guid>
    <pubDate>Thu, 13 Nov 2008 15:31:01 GMT</pubDate>
  </item>
  
  <item>
    <title>Re: Horrible JDBC Code and What&#039;s Wrong With It</title>
    <link>http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comment1226589298307</link>
    <description>
      Not terrible advice, but...

&lt;p&gt;Most of your points go straight at the problem definition, and not the code. The original code made obvious an assumption that all customer numbers were, well, numbers. Using a string when a number is mandated is pointless.

&lt;p&gt;The situations where exceptions exist for failure are also problem-domain related; the original code returned true or false, where false was apparently a catchall for &#034;all failure conditions, including invalid authentication.&#034;

&lt;p&gt;I&#039;d agree with you for the most part: throw an unchecked exception in the case of a service failure, and return a &#034;no user&#034; value for a non-matching condition. &amp;lt;code&amp;gt;boolean&amp;lt;/code&amp;gt; is a little too simple for this.
    </description>
    <author>Joseph B. Ottinger</author>
    <comments>http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comments</comments>
    <guid isPermaLink="true">http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comment1226589298307</guid>
    <pubDate>Thu, 13 Nov 2008 15:14:58 GMT</pubDate>
  </item>
  
  <item>
    <title>Re: Horrible JDBC Code and What&#039;s Wrong With It</title>
    <link>http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comment1226589016874</link>
    <description>
      @RJones:

It *is* example code, and isn&#039;t meant to be the end-all of login authentication.

As far as not catching exceptions other than SQLException... are you expecting them to be thrown? I&#039;m not. It&#039;d be silly of me to try to catch exceptions that the type system refuses to inform me of - because the exception system will tell me if an exception type will be thrown that requires my attention.

As far as runtime exceptions are concerned: the finally block will, in fact, clean up the resources as soon as the JVM allows it (if the JVM allows it.)

Setting the resources to null - when they&#039;re local references - may make you feel better, but it really does nothing to hint to the GC to &#034;collect these faster.&#034;

    </description>
    <author>Joseph B. Ottinger</author>
    <comments>http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comments</comments>
    <guid isPermaLink="true">http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comment1226589016874</guid>
    <pubDate>Thu, 13 Nov 2008 15:10:16 GMT</pubDate>
  </item>
  
  <item>
    <title>Re: Horrible JDBC Code and What&#039;s Wrong With It</title>
    <link>http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comment1226587412825</link>
    <description>
      I wold say do not concatenate the prepared statement string - immutable strings. That is also a was of cpu effort.&lt;br /&gt;
&lt;br /&gt;
I&#039;d say not all companies have numbers for customer id, therefore keeping it as a String still forces you to check it&#039;s not null/empty so that you don&#039;t waste a database connection. This could be true of the password as well, but we could never know what types are in the database anyways. Unless of course, a prepared statement was used.&lt;br /&gt;
&lt;br /&gt;
I&#039;d say the cardinal sin here is not using a PreparedStatement in order to spare the database and help with XSS or Sql injection. &lt;br /&gt;
&lt;br /&gt;
Then the nested rs.next() is pretty funny really. Never seen it before.&lt;br /&gt;
&lt;br /&gt;
Then the method should throw a runtime AuthenticationException, and a ServiceTemporarilyUnavailableException (after logging underlying exception) rather than a boolean value. &lt;br /&gt;
&lt;br /&gt;
etc.&lt;br /&gt;
    </description>
    <author>Anonymous</author>
    <comments>http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comments</comments>
    <guid isPermaLink="true">http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comment1226587412825</guid>
    <pubDate>Thu, 13 Nov 2008 14:43:32 GMT</pubDate>
  </item>
  
  <item>
    <title>Re: Horrible JDBC Code and What&#039;s Wrong With It</title>
    <link>http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comment1226584456242</link>
    <description>
      Even if your exception handling is not complete your code is flawed.&lt;br /&gt;
&lt;br /&gt;
You fail to catch any Exceptions outside SQLException. There should always be at least (and this includes examples) a standard Exception catch.&lt;br /&gt;
&lt;br /&gt;
For example you may wish to catch runtime exceptions. If you failed to do this you could fail to close ps and rs and leave them unclosed. &lt;br /&gt;
&lt;br /&gt;
Also I would null them as well after closing to let the GC know to collect them asap.&lt;br /&gt;
&lt;br /&gt;
And there are probably many others but I cannot be bothered right now.
    </description>
    <author>RJones</author>
    <comments>http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comments</comments>
    <guid isPermaLink="true">http://enigmastation.com:80/pebble/qotd/2008/11/12/1226498040000.html#comment1226584456242</guid>
    <pubDate>Thu, 13 Nov 2008 13:54:16 GMT</pubDate>
  </item>
  
  </channel>
</rss>
