title: how can I read from a big file and insert it to a database in java in a fast way
body: <p>I have this text file with this format</p>
  
  <pre><code>int | string | string | string |
  int | string | string | string |
  int | string | string | string |
  .
  .
  .
  </code></pre>
  
  <p>Size of this file is about 80 MB. I have to read this file and after some evaluation add it to the database. </p>
  
  <p>What I do is that I read one line and based on some condition I add them to the database. But this code is taking so long. It's been literally more than a day that I ran this code and no result yet! </p>
  
  <p>What can I do to make it faster.</p>
  
  <p>I know there should be some way to read the whole file at once.</p>
  
  <p>BTW I'm using mysql</p>
  
  <p>Help me out guys! </p>
  
  <p>Here is my code</p>
  
  <pre><code>public void fill_names_db() throws Exception{
  
      MySQLAccess dao = new MySQLAccess();   
      Scanner stringScanner;
  
  
  
      BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\havij\\Downloads\\taxdump\\names.dmp"));
  
      String tax_id;
      String name_txt;
      String unique_name;
      String name_class;
      Connection connect=null;
      connect = dao.newConnection();
  
  
  
      while (in.ready()) {
  
  
          String s = in.readLine();
          //System.out.println(s);
          stringScanner = new Scanner(s).useDelimiter("\t|\t");
  
          tax_id = stringScanner.next();
          stringScanner.next();
          name_txt = stringScanner.next();
          stringScanner.next();
          unique_name = stringScanner.next();
          stringScanner.next();
          name_class = stringScanner.next();
  
  
  
          if(name_class.equals("scientific name"))
              dao.insertToDB(connect, "id_to_name", tax_id.toString(), name_txt);
  
          if(dao.hasKey(connect,"name_to_id",name_txt))
              if (!unique_name.isEmpty())
                  dao.insertToDB(connect, "name_to_id",unique_name,tax_id.toString(),name_txt,unique_name, name_class );
  
          else if(!name_txt.isEmpty())
              dao.insertToDB(connect, "name_to_id",name_txt,tax_id.toString(),name_txt,unique_name, name_class );
  
  
      }
      dao.close(connect);
      in.close();
      System.out.println("done");
  
      }
  </code></pre>