Supported Engine Types
SuperSQL Engine
Standard Spark Engine
Standard Presto Engine
Note:
The Presto engine is deprecated and only available for existing users.
Preparing the Environment
Dependency: JDK 1.8
JDBC Download: Click to download the JDBC driver.
Connecting to DLC
1. Load the DLC JDBC driver.
Class.forName("com.tencent.cloud.dlc.jdbc.DlcDriver");
2. Create a Connection through DriverManager.
Connection cnct = DriverManager.getConnection(url, secretId, secretKey);
URL Format
jdbc:dlc:dlc.tencentcloudapi.com?task_type=SQLTask&database_name=abc&datasource_connection_name=DataLakeCatalog®ion=ap-nanjing&data_engine_name=spark-cu&result_type=COS&read_type=Stream
JDBC Connection String Parameter Description:
Parameter | Required | Description |
dlc_endpoint | Yes | The Endpoint for the DLC service, which is fixed as dlc.tencentcloudapi.com. |
datasource_connection_name | Yes | The name of the data source connection, which corresponds to the DLC data catalog. |
task_type | Yes | Task type. Presto engine: Enter SQLTask. For the SparkSQL engine or the standard engine SQL resource group, enter: SparkSQLTask. For the Spark job engine or the standard engine batch job, enter: BatchSQLTask. |
database_name | No | Database name. |
region | Yes | Region. Currently, the DLC service supports ap-nanjing, ap-beijing, ap-guangzhou, ap-shanghai, ap-chengdu, ap-chongqing, na-siliconvalley, ap-singapore, and ap-hongkong. |
data_engine_name | Yes | Data Engine Name |
secretId | Yes | The SecretId in TencentCloud API Key Management |
secretKey | Yes | The SecretKey in TencentCloud API Key Management |
Token | No | (Optional) The temporary token for a Tencent Cloud account, used in scenarios that involve logging in with temporary credentials. |
result_type | No | The default value is Service. If you require faster result retrieval, you can set it to COS. Service: Obtain results through the DLC API. COS: Obtain results through the COS client (not supported by the standard engine Presto). |
read_type | No | Stream: Obtain results from COS in a streaming manner. DownloadSingle: Download a single file to your local machine to obtain the result. The default value is Stream. This value is meaningful only when result_type is COS. The download location is the /tmp temporary directory. Ensure that the directory has read and write permissions. The data will be automatically deleted after it is read. |
resource_group_name | No | Standard Spark Engine Resource Group Name |
Execute the query
Statement stmt = cnct.createStatement();ResultSet rset = stmt.executeQuery("SELECT * FROM dlc");while (rset.next()){// process the results}rset.close();stmt.close();conn.close();}rset.close();stmt.close();conn.close();
Syntax Support
The syntax available for JDBC is consistent with the DLC standard syntax.
Sample Code
Database and Table Operations
import java.sql.*;public class MetaTest {public static void main(String[] args) throws SQLException {try {Class.forName("com.tencent.cloud.dlc.jdbc.DlcDriver");} catch (ClassNotFoundException e) {e.printStackTrace();return;}Connection connection = DriverManager.getConnection("jdbc:dlc:<dlc_endpoint>?task_type=<task_type>&database_name=<database_name>&datasource_connection_name=DataLakeCatalog®ion=<region>&data_engine_name=<data_engine_name>&result_type=<result_type>","<secret_id>","secret_key");Statement statement = connection.createStatement();String dbName = "dlc_db1";String createDatabaseSql = String.format("CREATE DATABASE IF NOT EXISTS %s", dbName);statement.execute(createDatabaseSql);String tableName = "dlc_t1";String wholeTableName = String.format("%s.%s", dbName, tableName);String createTableSql =String.format("CREATE EXTERNAL TABLE %s ( "+ " id string , "+ " name string , "+ " status string , "+ " type string ) "+ "ROW FORMAT SERDE "+ " 'org.apache.hadoop.hive.ql.io.orc.OrcSerde' "+ "STORED AS INPUTFORMAT "+ " 'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat' "+ "OUTPUTFORMAT "+ " 'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat' "+ "LOCATION\\n"+ " 'cosn://<bucket_name>/<path>' ",wholeTableName);statement.execute(createTableSql);// get meta dataDatabaseMetaData metaData = connection.getMetaData();System.out.println("product = " + metaData.getDatabaseProductName());System.out.println("jdbc version = "+ metaData.getDriverMajorVersion() + ", "+ metaData.getDriverMinorVersion());ResultSet tables = metaData.getTables(null, dbName, tableName, null);while (tables.next()) {String name = tables.getString("TABLE_NAME");System.out.println("table: " + name);ResultSet columns = metaData.getColumns(null, dbName, name, null);while (columns.next()) {System.out.println(columns.getString("COLUMN_NAME") + "\\t" +columns.getString("TYPE_NAME") + "\\t" +columns.getInt("DATA_TYPE"));}columns.close();}tables.close();statement.close();connection.close();}}
Data Query
import java.sql.*;public class DataTest {public static void main(String[] args) throws SQLException {try {Class.forName("com.tencent.cloud.dlc.jdbc.DlcDriver");} catch (ClassNotFoundException e) {e.printStackTrace();return;}Connection connection = DriverManager.getConnection("jdbc:dlc:<dlc_endpoint>?task_type=<task_type>&database_name=<database_name>&datasource_connection_name=DataLakeCatalog®ion=<region>&data_engine_name=<data_engine_name>&result_type=<result_type>","<secret_id>","secret_key");Statement statement = connection.createStatement();String sql = "select * from dlc_test";statement.execute(sql);ResultSet rs = statement.getResultSet();while (rs.next()) {System.out.println(rs.getInt(1) + ":" + rs.getString(2));}rs.close();statement.close();connection.close();}}
Database Client
Load the DLC JDBC driver package into your SQL client, connect to the DLC service, and run queries.
Prerequisites
1. The Data Lake Compute service has been activated.
2. The JDBC driver package mentioned above has been downloaded.
3. SQL Workbench/J has been downloaded and installed.
Operation Steps
1. Create a DLC Driver using the JDBC driver package.

2. Connect to DLC, enter the following parameters, click test, and complete the connection to DLC after the test passes.
Name: The connection name, which is used to identify the connection to DLC.
Username: Corresponds to the secret_id of a Tencent Cloud user.
Password: Corresponds to the secret_key of a Tencent Cloud user.
URL: The URL used to connect to DLC. Its format is the same as the URL for creating a connection via JDBC mentioned above.

3. View database and table information.

4. Query data.
