ExportDataUsingSQL.java
The following sample code exports/fetches data from Zoho Reports using a SQL SELECT query. This is done using Zoho Reports CloudSQL, which enables you to use SQL select query to fetch data from any of your Zoho Reports database.
In this example we are fetching the rows from the "Sales" table matching the " Region" as 'East" using a SELECT query.
Before trying it out
- Take a copy of the Store Sales database.
- Change the configurations in Config.java
import java.io.*;
import com.adventnet.zoho.client.report.*;
public class ExportDataUsingSQL { private ReportClient rc = Config.getReportClient(); public void exportData() throws Exception { String uri = rc.getURI(Config.LOGINEMAILID,Config.DATABASENAME); String sql = "select "Customer Name",Sales,Cost,Profit from Sales where Region = 'East'"; File expFile = new File("ExportedDataUsingSQL.csv"); System.out.println("Exporting data using sql." + sql); rc.exportDataUsingSQL(uri,"CSV",expFile,sql,null); System.out.println("Data successfully exported to " + expFile.getAbsolutePath()); } public static void main(String[] args) throws Exception { ExportDataUsingSQL exp = new ExportDataUsingSQL(); //call EXPORT API with the same logged in session exp.exportData(); } }