PreparedStatement ps_entry = _conn.prepareStatement("INSERT INTO entry_" + name + "(id,entry) VALUES(?,?)"); PreparedStatement ps_lemma = _conn.prepareStatement("INSERT INTO lemma_" + name + "(lemma,id,origin,lemma_lower) VALUES(?,?,?,?)");
PreparedStatement ps_entry = _conn.prepareStatement("INSERT INTO \"entry_" + name + "\"(id,entry) VALUES(?,?)"); PreparedStatement ps_lemma = _conn.prepareStatement("INSERT INTO \"lemma_" + name + "\"(lemma,id,origin,lemma_lower) VALUES(?,?,?,?)");
  private void index(String path, String name)  {    try     {           long fileSize = new File(path).length();      _bytesRead = 0;            // initialisation      InputStreamReader reader = new InputStreamReader(        new FileInputStream(path));            _saxHandler = new SaxHandler();            Random rand = new Random();      XMLReader xr = XMLReaderFactory.createXMLReader();      xr.setContentHandler(_saxHandler);                  PreparedStatement ps_entry = _conn.prepareStatement("INSERT INTO entry_"         + name + "(id,entry) VALUES(?,?)");      PreparedStatement ps_lemma = _conn.prepareStatement("INSERT INTO lemma_" + name                      + "(lemma,id,origin,lemma_lower) VALUES(?,?,?,?)");      String entry;      byte[] piLeft = new byte[] {0,0,0,0,0,0};      byte[] piRight = new byte[] {0,0,0,0,0,0,0};            while(!_shallStop && (entry = getInnerText(reader, "<entry", piLeft, "</entry", piRight)) != null)      {        entry = entry + ">";        //parse the xml (only entry)        try        {          _saxHandler.lastLemmaInEntry.clear();          _saxHandler.lastIdInEntry = null;          InputSource src = new InputSource(new java.io.ByteArrayInputStream(entry.getBytes()));          xr.parse(src);          // add it to the database          int size = _saxHandler.lastLemmaInEntry.size();          if(size != 0)          {            if(_saxHandler.lastIdInEntry == null)            {              // random number              _saxHandler.lastIdInEntry = name + "-" + rand.nextInt();            }            ps_entry.setString(1, _saxHandler.lastIdInEntry);            ps_entry.setString(2, entry);            ps_entry.executeUpdate();            Iterator<String> it = _saxHandler.lastLemmaInEntry.iterator();            while(it.hasNext())            {              String l = it.next();              ps_lemma.setString(1, l);              ps_lemma.setString(2, _saxHandler.lastIdInEntry);              ps_lemma.setString(3, name);              ps_lemma.setString(4, l.toLowerCase()); // needed due comparison bug of SQLite              ps_lemma.executeUpdate();            }          }        }        catch(SAXException saxEx)        {          saxEx.printStackTrace();        }                _importProgress = (((double) _bytesRead / (double) fileSize)*100);      }      //      // search for "<entry"//      int c;//      int q1 = 0; // count of already read in characters of "<entry" (KMP)//      char[] P1 = new char[] {'<','e','n','t','r','y'};//      byte[] J1 = new byte[] {0,0,0,0,0,0};//      while((c = reader.read()) > -1)//      {//        while(q1 > 0 && P1[q1] != (char) c)//          q1 = J1[q1-1];//        //        if(P1[q1] == (char) c)//          q1++;//        //        if(q1 == P1.length)//        {//          q1 = J1[q1-1];//          //          // found, now find the end ("</entry" and add it to the database//          String entry = "<entry";//          int q2 = 0; // again KMP//          char[] P2 = new char[] {'<', '/', 'e', 'n', 't', 'r', 'y'};//          byte[] J2 = new byte[] {0,0,0,0,0,0,0};//          boolean found = false;//          while(!found && (c = reader.read()) > -1)//          {//           //            while(q2 > 0 && P2[q2] != (char) c)//              q2 = J2[q2-1];//            //            if(P2[q2] == (char) c)//              q2++;//            //            if(q2 == P2.length)//            {//              found = true;//              q2 = J2[q2-1];//              entry = entry + "y>";//              //              //parse the xml (only entry)//              try//              {//                _saxHandler.lastLemmaInEntry.clear();//                _saxHandler.lastIdInEntry = null;//                InputSource src = new InputSource(new java.io.ByteArrayInputStream(entry.getBytes()));//                xr.parse(src);//                //                // add it to the database//                int size = _saxHandler.lastLemmaInEntry.size();//                if(size != 0)//                {//                  if(_saxHandler.lastIdInEntry == null)//                  {//                    // random number//                    _saxHandler.lastIdInEntry = name + "-" + rand.nextInt();//                  }//                  ps_entry.setString(1, _saxHandler.lastIdInEntry);//                  ps_entry.setString(2, entry);//                  ps_entry.executeUpdate();//                  //                  //                  Iterator<String> it = _saxHandler.lastLemmaInEntry.iterator();//                  //                  while(it.hasNext())//                  {//                    String l = it.next();//                    ps_lemma.setString(1, l);//                    ps_lemma.setString(2, _saxHandler.lastIdInEntry);//                    ps_lemma.setString(3, name);//                    ps_lemma.setString(4, l.toLowerCase()); // needed due comparison bug of SQLite//                    ps_lemma.executeUpdate();//                  }//                  //                }//                //              }//              catch(SAXException saxEx)//              {//                saxEx.printStackTrace();//              }//            }//            else//            {//              entry = entry + (char) c;//            }//          }//        }//        //      }            ps_entry.close();      ps_lemma.close();            reader.close();          } catch (Exception ex) {      ex.printStackTrace();    }      }