Skip to content

How to import data with getGeoLocation twitter4j to MySQL using Java Netbeans

I want to execute my Twitter crawling using Java importing data to MySQL. My problem is when I set parameter for getGeoLocation, which contained latitude and longitude, then I found something error.

GeoLocation geoLocation = status.getGeoLocation();
    
    stmt = conne.prepareStatement("INSERT INTO tweet(ID,date,name,coordinate) VALUES (?,?,?,?)");

    stmt.setInt(1, (int) status.getId());
    stmt.setString(2, getTimeStamp());
    stmt.setString(3, status.getUser().getScreenName());
 if (status.getGeoLocation() != null){
    stmt.setDouble(4, status.getGeoLocation().getLongitude() && status.getGeoLocation().getLatitude());                                                                           
  }  

The output said it is hard to specify for parameter 4 (geoLocation):

enter image description here

Many thanks for any comment!

Answer

Your query expects 4 parameters to be passed, but in your Java code the 4th one is set only when if condition is met. In the opposite case the last parameter is not passed resulting in exception.

If the case when the last parameter is not passed is legal then I’d suggest to create one more query with only three params and use it.