Java: Which is the better way to structure methods
<p>I don't have a ton of knowledge about Java, so I was wondering if someone could give me an idea about the best way to structure this application (or whether it even matters).</p>

<p>I have a situation where I am pulling data from a flat file and committing it to a SQL database. However, the particular prepared statement that I use depends on the file extension.</p>

<h2>So essentially</h2>

<ol>
<li>program checks the file extension.</li>
<li>Opens file, creates buffered reader - reads string data.</li>
<li>based on file extension, generates prepared statement.</li>
<li>Adds prepared statement to batchlist.</li>
<li>Repeats for each line in the file (there could be thousands of lines).</li>
<li>Executes the prepared statements.</li>
</ol>

<p>The way that I determine how to get from file extension to appropriate prepared statement is a Map (which calls the relevant method from a bunch that all implement the same interface).</p>

<p>There are two ways I could implement this.</p>

<ol>
<li><p>Pass the connection and the buffered reader to the appropriate method and it will do all the work (generate thousands of prepared statements and execute them. The method returns 'void').</p></li>
<li><p>Pass the connection and the string for a line to the appropriate method. The method returns the prepared statement. The original application generates another string (the next line), passes it to the method which returns a prepared statement, etc...until the original application executes all of the prepared statements.</p></li>
</ol>

<p>Essentially, option number 1 requires more code and option number 2 requires thousands of method calls.</p>

<p>Oh and it might be important to note that each method call is conditional based on using the ".equals()" method to check a string against the appropriate key in the map.</p>

<p>Thanks.</p>
