JDBC Driver for Zoho Analytics CloudSQL

CloudSQL enables users to execute SQL queries on structured data stored in Zoho Analytics, it also lends itself naturally to support Database Connectivity Standard like JDBC (Java Database Connectivity). Developers who are familiar using JDBC driver for connectivity to databases, can now use Zoho Analytics CloudSQL JDBC driver to connect and execute the necessary SQL queries.

With the availablity of this JDBC driver, developers need not learn the Zoho Analytics CloudSQL HTTP Web API to execute the SQL query. They just have know how to use the Zoho Analytics JDBC driver and start interacting with the service, the same way as they would interact with a Workspace using a JDBC standard driver.

  • Zoho Analytics JDBC Driver Download
  • Zoho Analytics JDBC Driver
    • JDBC Connection URL for Zoho Analytics
    • Sample
    • Jars to be kept in CLASSPATH for JDBC Driver
    • JDBC Type Mapping with Zoho Analytics Data types
  • Connecting Zoho Analytics from Workspace Visualization Tools
    • DBVisualizer
    • Squirrel SQL Client

ZOHO ANALYTICS JDBC DRIVER DOWNLOAD

Download the Zoho Analytics JDBC Driver from the below link.

https://downloads.zohocdn.com/analytics-api-desktop/jdbc/ZohoCloudSQLJDBC_1_0.zip 

JAVADOCS

ZOHO ANALYTICS JDBC DRIVER

To use the JDBC Driver you need to have a zoho login email address and password. Currently you could only execute Select queries using the JDBC driver. Other SQL statements will be supported soon.

In JDBC, the DriverManager class manages the establishment of connections. DriverManager needs to be told which JDBC driver it should try to make connections with. The way to do this is to use Class.forName( ) on the class that implements java.sql.Driver interface.

Refer to the Zoho Analytics JDBC Driver javadocs to know more about the same. Click to download Zoho Analytics JDBC Driver.

JDBC CONNECTION URL FOR ZOHO ANALYTICS

https://analyticsapi.zoho.com/api/<zoho_username_dbowner>/<Workspacename>

SAMPLE

The sample code is shown in the code block.

JARS TO BE KEPT IN CLASSPATH FOR JDBC DRIVER

All the jars from 'ZohoCloudSQLJDBC_1_0/Zoho/CloudSQLJDBCDriver/lib’ directory within the JDBC Driver Zip need to be kept in CLASSPATH for JDBC driver.

JDBC TYPE MAPPING WITH ZOHO ANALYTICS DATA TYPES

The following table provides the mapping between the Zoho Analytics data types and the JDBC SQL types. Use this mapping to process the data fetched from Zoho Analytics in your Java code.

Zoho Analytics Data typeJDBC SQL Type
Plain TextVARCHAR
Multi Line TextLONGVARCHAR
EmailVARCHAR
Auto NumberBIGINT
NumberBIGINT
Positive NumberBIGINT
Decimal NumberDOUBLE
CurrencyDOUBLE
PercentDOUBLE
DateTIMESTAMP
Decision BoxBIT

CONNECTING ZOHO ANALYTICS FROM WORKSPACE VISUALIZATION TOOLS

Zoho Analytics JDBC Driver supports connecting Zoho Analytics from the following Workspace Visualizations tools.

  • DBVisualizer
  • Squirrel SQL Client
     

Sample:

Copiedimport java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

public class ZohoReportsCloudSQL
{
    public static void main(String args[])
    {
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        try
        {
            Class.forName("com.zoho.cloudsql.jdbc.ZohoReportsDriver");
            Properties conProps = new Properties();
            
            // ZohoAnalytics admin emailaddress
            conProps.put("user","david.s@zoho.com");

            // ZohoAnalytics OAuth authentication parameters
            conProps.put("CLIENT_ID","");
            conProps.put("CLIENT_SECRET","");
            conProps.put("REFRESH_TOKEN","");
            
            // Uncomment this incase you need proxy settings
            /*
            // Proxy host name to connect the internet
            conProps.put("PROXYSERVER","proxy_hostname");
            // Proxy port to connect the internet
            conProps.put("PROXYPORT","proxy_port");
            // Proxy user name to connect the internet
            conProps.put("PROXYUSERNAME","proxy_username");
            // Proxy password to connect the internet
            conProps.put("PROXYPASSWORD","proxy_password");
            */
            /* Important Note: Connection is single threaded in Zoho Analytics */
            // david.s@zoho.com is the admin of the Workspace 'Sales'
            con = DriverManager.getConnection("https://analyticsapi.zoho.com/api/david.s@zoho.com/Sales",conProps);
            stmt = con.createStatement();
            String sql ="select * from <tablename>";
            rs = stmt.executeQuery(sql);
        }
        catch(SQLException se)
        {
            // handle any errors
            System.out.println("SQLException: " + se.getMessage());
            System.out.println("Zoho Analytics Error code: " + se.getErrorCode());
        }
        catch(Exception e)
        {
            // handle the exception
        }
        finally
        {
            if(rs != null)
            {
                try
                {
                    rs.close();
                }
                catch(SQLException sqlEx) { } // ignore
            }
            if(stmt != null)
            {
                try
                {
                    stmt.close();
                }
                catch (SQLException sqlEx) { } // ignore
            }
            if(con != null)
            {
                try
                {
                    con.close();
                }
                catch (SQLException sqlEx) { } // ignore
            }
        }
    }
}

The example Java code snippet shows how you can register Zoho Analytics CloudSQL JDBC driver, obtain a Connection, create a Statement and execute the query.