title: Read multiple text files in a folder and import to database
body: <p>I need to import bunch of text files(292) into different database. Each file has to be in different table and database. It will retrieve doc_no and doc_cde from table sys_doc. My idea is to use a loop. Also wondering how could I filter this text files according to their database,based on the doc_cde. </p>
  
  <p>This is the sample of code I think I will use right now. Any other ideas to do my task will be helpful.          </p>
  
  <pre><code>import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.Statement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  
  public class automateImport
  {
     public static void main(String[] args) 
     {
         DBase db = new DBase();
         Connection conn = db.connect("jdbc:mysql://localhost:3306/test","root","caspian");
         db.importData(conn,args[0]);
     }
  
  }
  
  class DBase
  {
      public DBase(){}
  
      public Connection connect(String db_connect_str, 
      String db_userid, String db_password)
      {
          Connection conn;
          try
          {
             Class.forName("com.mysql.jdbc.Driver").newInstance();
  
              conn = DriverManager.getConnection(db_connect_str, 
              db_userid, db_password);
  
          }
          catch(Exception e){
              e.printStackTrace();
              conn = null;
          }
  
          return conn;    
      }
  
      public void importData(Connection conn,String filename)
      {
          Statement stmt;
          String query;
  
          try
          {
              stmt = conn.createStatement(
              ResultSet.TYPE_SCROLL_SENSITIVE,
              ResultSet.CONCUR_UPDATABLE);
  
              query = "LOAD DATA INFILE '"+filename+
                       "' INTO TABLE testtable (text,price);";
  
              stmt.executeUpdate(query);
  
          }
          catch(Exception e){
              e.printStackTrace();
              stmt = null;
          }
      }
  };
  </code></pre>