I am referring this thread :
Twitter - Query for tweets within a radius of a particular GeoLocation
But my problem is I want to directly import it into database MySQL, instead of System.out.println. How to do that?
I have this code in this far :
stmt = conne.prepareStatement("INSERT INTO tweet(ID,date,name,text) VALUES (?,?,?,?)");
stmt.setInt(1, (int) status.getId());
stmt.setString(2, getTimeStamp());
stmt.setString(3, status.getUser().getScreenName());
Query query = new Query("india");
GeoLocation location = new GeoLocation(20.593684, 78.962880);
String unit = Query.KILOMETERS;
query.setGeoCode(location, 2, unit);
QueryResult result;
result = twitter.search(query);
List<Status> tweets = result.getTweets();
for (Status tweet : tweets){
stmt.setString(4, status.getText());
}
Then, I see the output error like this :
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Cannot use this builder any longer, build() has already been called
I figured out that I have two build(), that is one for TwitterStream and one for TwitterFactory :
TwitterStream twitterStream5 = new TwitterStreamFactory(cb5.build()).getInstance();
TwitterFactory tf = new TwitterFactory(cb5.build());
Twitter twitter = tf.getInstance();
But still, I do not know how to correct it. Thank you for any comment !
The problem is more about builder itself: you cannot reuse it after
build()was called. You should have two separate builders.