title: How to keep the sql queries out of the java code
body: <p>I've written a small code which functions like follows:</p>
  
  <ol>
  <li>Read an input file </li>
  <li>Read the first line in it and check if it
  has value <code>AAA</code> at a certain position </li>
  <li>if it satisfies the
  condition call the method <code>insertAAAmethod</code> and load the data to the
  oracle table</li>
  <li>read the next line if it is record <code>BBB</code> call the <code>insertBBBrmethod</code> which has   different insert query</li>
  </ol>
  
  <p>The problem is I have 15 different records in the input file so I have 15 different methods like <code>insertAAAmethod</code> each with different insert query:</p>
  
  <pre><code>public static void insertAAARecord() throws Exception {
  
      String sqlQuery = "insert into my_table(ColumnA,ColumnB,ColumnC,ColumnD,ColumnE,ColumnF,ColumnG)"
              + "values (?,?,?,?,?,?,?)";
  
      try {
  
          pstmt = conn.prepareStatement(sqlQuery);
  
          pstmt.setString(1, "AAA");
          pstmt.setDate(2,
                  StringtoDate("AAA", CurrentLine.substring(150, 158)));
          pstmt.setDate(3,
                  StringtoDate("AAA", CurrentLine.substring(158, 166)));
          pstmt.setString(4, CurrentLine.substring(24, 34));
          pstmt.setString(5, CurrentLine.substring(37, 45));
          pstmt.setString(6, CurrentLine.substring(147, 150));
          pstmt.setDate(7, headerDate);
  
          pstmt.executeUpdate();
      } catch (SQLException e) {
          e.printStackTrace(System.out);
  
      } finally {
  
          pstmt.close();
  
      }
  
  }
  </code></pre>
  
  <p>Is it possible to keep the sql query out of the java code? (Like in a properties file, for example)</p>
  
  <p><strong>Note:</strong> The insert query changes as per the record if it is record 'AAA' it should follow one insert query if the record is different insert query should change..</p>
  
  <p>Let me know how to optimize my code.</p>