ImportData.java
The following sample code is for importing data in a CSV file into a table. In this example, the data in the file "StoreSales.csv" present in the local(/client) machine is appended to the table "Sales".
Before trying it out
- Take a copy of the Store Sales database
- Change the configurations in Config.java
- Ensure that you have a copy of the StoreSales.csv and update the location.
- The file is bundled along with the samples.
public class ImportData
{
public static void importData()
throws Exception
{
File csvFile = new File("StoreSales.csv"); //Update the location.
if (!csvFile.exists())
{
throw new RuntimeException(" File " + csvFile.getAbsolutePath()
+ " does not exist."
+ "Update the csvFile variable to point to the proper location.");
}
ReportClient rc = Config.getReportClient();
rc.login(Config.LOGINNAME,Config.PASSWORD);
String uri = rc.getURI(Config.LOGINNAME,Config.DATABASENAME,"Sales");
rc.importData(uri,"APPEND",csvFile,getImportConfig(),false);
rc.logout();
}
private static Map getImportConfig()
{
HashMap config = new HashMap();
config.put("ZOHO_AUTO_IDENTIFY","true");
config.put("ZOHO_ON_IMPORT_ERROR","ABORT");
config.put("ZOHO_CREATE_TABLE","false");
return config;
}
public static void main(String[] args)
throws Exception
{
importData();
}
}