2013-04-20 6 views
6

हैलो मैं अपने जावा एप्लिकेशन से सोलर में अपने डेटाबेस में एक पंक्ति को इंडेक्स करने का प्रयास करता हूं। मैंने जरूरी जार जोड़े हैं, लेकिन मुझे यह त्रुटि मिल रही है। मेरे Solr स्कीमा सही त्रुटिधागे "मुख्य" java.lang में अपवाद ..NoSuchFieldError: DEF_CONTENT_CHARSET

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 
SLF4J: Defaulting to no-operation (NOP) logger implementation 
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 
Exception in thread "main" java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET 
    at org.apache.http.impl.client.DefaultHttpClient.setDefaultHttpParams(DefaultHttpClient.java:175) 
    at org.apache.http.impl.client.DefaultHttpClient.createHttpParams(DefaultHttpClient.java:158) 
    at org.apache.http.impl.client.AbstractHttpClient.getParams(AbstractHttpClient.java:448) 
    at org.apache.solr.client.solrj.impl.HttpClientUtil.setFollowRedirects(HttpClientUtil.java:223) 
    at org.apache.solr.client.solrj.impl.HttpClientConfigurer.configure(HttpClientConfigurer.java:58) 
    at org.apache.solr.client.solrj.impl.HttpClientUtil.configureClient(HttpClientUtil.java:115) 
    at org.apache.solr.client.solrj.impl.HttpClientUtil.createClient(HttpClientUtil.java:105) 
    at org.apache.solr.client.solrj.impl.HttpSolrServer.<init>(HttpSolrServer.java:155) 
    at org.apache.solr.client.solrj.impl.HttpSolrServer.<init>(HttpSolrServer.java:128) 
    at tan.indexSolr.<init>(indexSolr.java:195) 
    at tan.indexSolr.main(indexSolr.java:51) 

यहाँ है और मैं अनुरोध बस अपना डेटाबेस के लिए नई पंक्ति जोड़ने के बनाने के लिए और मैं यह भी

यहाँ सूचीबद्ध किए जा करना चाहते है मेरे कोड

public class indexSolr { 
    private Connection conn = null; 
    private static HttpSolrServer server; 
     private Collection docs = new ArrayList(); 
     private int _totalSql = 0; 
     private long _start = System.currentTimeMillis(); 


    public static void main(String[] args) throws SolrServerException, IOException, SQLException 
    { String url = "http://localhost:8983/solr/db"; 



    indexSolr idxer = new indexSolr(url); 

    idxer.doSqlDocuments(); 

    idxer.endIndexing(); 




    } 

    private void doSqlDocuments() throws SQLException { 

     try { 
      Class.forName("org.postgresql.Driver"); 

      conn = DriverManager.getConnection(
        "jdbc:postgresql://localhost:5432/biz_cat", 
        "postgres", "pos"); 
      java.sql.Statement st = null; 
      st = conn.createStatement(); 
      ResultSet rs = st.executeQuery("select * from pl_biz order by id DESC LIMIT 1"); 

      while (rs.next()) { 

      SolrInputDocument doc = new SolrInputDocument(); 

      Integer id = rs.getInt("id"); 
      String name = rs.getString("name"); 
      String midname = rs.getString("midname"); 
      String lastname = rs.getString("lastname"); 
      String frlsname = rs.getString("frlsname"); 
      String biz_subject = rs.getString("biz_subject"); 
      String company_type = rs.getString("company_type"); 
      String obshtina = rs.getString("obshtina"); 
      String main_office_town = rs.getString("main_office_town"); 
      String address = rs.getString("address"); 
      String role = rs.getString("role"); 
      String country = rs.getString("country"); 
      String nace_code = rs.getString("nace_code"); 
      String nace_text = rs.getString("nace_text"); 
      String zip_code = rs.getString("zip_code"); 
      String phone = rs.getString("phone"); 
      String fax = rs.getString("fax"); 
      String email = rs.getString("email"); 
      String web = rs.getString("web"); 
      String location = rs.getString("location"); 
      String geohash = rs.getString("geohash"); 
      Integer popularity = rs.getInt("popularity"); 

      doc.addField("id", id); 
      doc.addField("name", name); 
      doc.addField("midname", midname); 
      doc.addField("lastname", lastname); 
      doc.addField("frlsname", frlsname); 
      doc.addField("biz_subject", biz_subject); 
      doc.addField("company_type", company_type); 
      doc.addField("obshtina", obshtina); 
      doc.addField("main_office_town", main_office_town); 
      doc.addField("address", address); 
      doc.addField("role", role); 
      doc.addField("country", country); 
      doc.addField("nace_code", nace_code); 
      doc.addField("nace_text", nace_text); 
      doc.addField("zip_code", zip_code); 
      doc.addField("phone", phone); 
      doc.addField("fax", fax); 
      doc.addField("email", email); 
      doc.addField("web", web); 
      doc.addField("location", location); 
      doc.addField("geohash", geohash); 
      doc.addField("popularity", popularity); 


      docs.add(doc); 
      ++_totalSql; 


      if (docs.size() > 1) { 
       // Commit within 5 minutes. 
       UpdateResponse resp = server.add(docs); 
       System.out.println (resp); 
       if (resp.getStatus() != 0) { 
       log("Some horrible error has occurred, status is: " + 
         resp.getStatus()); 
       } 
       docs.clear(); 
      } 
      } 
     } 
     catch (Exception ex) 
     { 
      ex.printStackTrace(); 
     } 
     finally { 
      if (conn != null) { 
      conn.close(); 
      } 
     } 


    } 

    private void endIndexing() throws IOException, SolrServerException { 
      if (docs.size() > 0) { // Are there any documents left over? 
       server.add(docs, 300000); // Commit within 5 minutes 
      } 
      try 
      { 
      server.commit(); 

      } 
      catch (Exception ex) 
      { 

       ex.printStackTrace(); 
      } 


      long endTime = System.currentTimeMillis(); 
      log("Total Time Taken: " + (endTime - _start) + 
       " milliseconds to index " + _totalSql + 
       " SQL rows"); 
      } 


      private static void log(String msg) { 
      System.out.println(msg); 
      } 


      private indexSolr(String url) throws IOException, SolrServerException { 
       // Create a multi-threaded communications channel to the Solr server. 
      try {  
      server = new HttpSolrServer(url); 

      server.setSoTimeout(1000); // socket read timeout 
      server.setConnectionTimeout(1000); 
      server.setMaxRetries(1); 


      } 
       catch (Exception ex) 
       { 

        ex.printStackTrace(); 

       } 
      } 

} 
+5

NoSuchFieldError लगभग हमेशा असंगत संस्करणों के कारण होता है। आपके पास एचटीपी क्लाइंट का क्या संस्करण है? क्या आप मेवेन का उपयोग कर रहे हैं? क्या यह संभव है कि आपके पास HttpClient के कई संस्करण हैं? इन चीजों की जांच करें और आपको अपना जवाब मिलना चाहिए। – Pace

+0

धन्यवाद कि समस्या थी –

उत्तर

1

This answer has been taken from the comment, by @Pace on the 20th of April 2013

I've marked it as a community wiki post, as advised by Question with no answers, but issue solved in the comments .


NoSuchFieldError लगभग हमेशा असंगत संस्करणों के कारण होता है।

आपके पास HttpClient का कौन सा संस्करण है? क्या आप मेवेन का उपयोग कर रहे हैं? क्या यह संभव है कि आपके पास HttpClient के कई संस्करण हैं?
इन चीजों की जांच करें और आपको अपना उत्तर मिलना चाहिए।

संबंधित मुद्दे