Thursday, August 30, 2012

Eclipse stuck on Workspace building

If your Eclipse is freezing during Workspace building, try to do following:

  • Close/Kill Eclipse
  • Go to your Workspace folder
  • Go to .metadata\.plugins\org.eclipse.core.resources\projects folder
  • Move the content to any temporary directory
  • Start Eclipse


If Eclipse is not coming up, move back the content of the folder.

Wednesday, August 29, 2012

How to initialize a java.util.Map inline

If you're declaring a Map which will contain some constant values, you can add necessary data to this Map inline:

Map<String, String> map = new HashMap<String, String>() {{
  put("1", "value 1");
  put("2", "value 2");
  put("3", "value 3");
}};

Monday, August 27, 2012

Check that ResultSet is not empty

I think it's most common method to find if ResultSet is empty, and then to loop through results:

if (resultSet.next()) {
  do {
    //your code
  } while (resultSet.next());
}
else {
  // throw an Exception
}