diff --git a/docs-en/05-develop/01-connect/01-python.md b/docs-en/05-develop/01-connect/01-python.md index 65c327a5c4eeb2fa9aea549835403c6454e15452..9a9ce5c08745428293fe58e1393c7246a873e3fd 100644 --- a/docs-en/05-develop/01-connect/01-python.md +++ b/docs-en/05-develop/01-connect/01-python.md @@ -5,7 +5,49 @@ title: Connect with Python Connector ## Install Connector +First, you need to install the `taospy` module. Run the command below in your terminal. + +``` +pip3 install taospy +``` + +You'll need to have Python3 installed. + ## Config +Run this command in your terminal to save connect parameters as environment variables: + +``` +export TDENGINE_CLOUD_HOST= +export TDENGINE_CLOUD_PORT= +export TDENGINE_CLOUD_TOKEN= +export TDENGINE_USER_NAME= +export TDENGINE_PASSWORD= +``` + + + +:::note +You should replace above placeholders as real values. To get these values, please log in TDengine Cloud and switch to "Connector" section. + +::: + + ## Connect +```python +import taosrest +import os + +host = os.environ["TDENGINE_CLOUD_HOST"] +port = os.environ["TDENGINE_CLOUD_PORT"] +token = os.environ["TDENGINE_CLOUD_TOKEN"] +user = os.environ["TDENGINE_USER_NAME"] +password = os.environ["TDENGINE_PASSWORD"] + +conn = taosrest.connect(host=host, + port=port, + username="root", + password="taosdata", + token=token) +``` diff --git a/docs-en/05-develop/01-connect/02-java.md b/docs-en/05-develop/01-connect/02-java.md index 06d207f0561d225e88353fc230830a1b92d09b1e..98ae74749c1f591df1eecc128c4dfa58c9537926 100644 --- a/docs-en/05-develop/01-connect/02-java.md +++ b/docs-en/05-develop/01-connect/02-java.md @@ -3,8 +3,68 @@ sidebar_label: Java title: Connect with Java Connector --- -## Install Connector +## Add Dependency + +Build with Maven + +``` + + com.taosdata.jdbc + taos-jdbcdriver + 2.0.38 + +``` + +Build with Gradle + +``` +dependencies { + implementation 'com.taosdata.jdbc:taos-jdbcdriver:2.0.39' +} +``` ## Config -## Connect \ No newline at end of file +Run this command in your terminal to save connect parameters as environment variables: + +``` +export TDENGINE_CLOUD_HOST= +export TDENGINE_CLOUD_PORT= +export TDENGINE_CLOUD_TOKEN= +export TDENGINE_USER_NAME= +export TDENGINE_PASSWORD= +``` + + +:::note +You should replace above placeholders as real values. To get these values, please log in TDengine Cloud and switch to "Connector" section. + +::: + + +## Connect + +```java +import com.taosdata.jdbc.TSDBDriver; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Properties; + +public class ConnectCloudExample { + public static void main(String[] args) throws SQLException { + String host = System.getenv("TDENGINE_CLOUD_HOST"); + String port = System.getenv("TDENGINE_CLOUD_PORT"); + String token = System.getenv("TDENGINE_CLOUD_TOKEN"); + String user = System.getenv("TDENGINE_USER_NAME"); + String password = System.getenv("TDENGINE_PASSWORD"); + String jdbcUrl = String.format("jdbc:TAOS-RS://%s:%s?user=%s&password=%s", host, port, user, password); + Properties connProps = new Properties(); + connProps.setProperty(TSDBDriver.PROPERTY_KEY_TOKEN, token); + Connection conn = DriverManager.getConnection(jdbcUrl); + System.out.println("Connected"); + conn.close(); + } +} +``` \ No newline at end of file diff --git a/docs-en/09-connector/python.md b/docs-en/09-connector/python.md index 325840966ae40a3abaa70e40d02f42271d5f26ee..1afe0af62b691fac32c5bf57be7673c15505bc38 100644 --- a/docs-en/09-connector/python.md +++ b/docs-en/09-connector/python.md @@ -1 +1 @@ -# Python Connector \ No newline at end of file +# Python Connector diff --git a/docs-examples/java/src/main/java/com/taos/example/ConnectCloudExample.java b/docs-examples/java/src/main/java/com/taos/example/ConnectCloudExample.java new file mode 100644 index 0000000000000000000000000000000000000000..12109f79482a8a15743241bfbacf9340db18cce7 --- /dev/null +++ b/docs-examples/java/src/main/java/com/taos/example/ConnectCloudExample.java @@ -0,0 +1,23 @@ +package com.taos.example; +import com.taosdata.jdbc.TSDBDriver; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Properties; + +public class ConnectCloudExample { + public static void main(String[] args) throws SQLException { + String host = System.getenv("TDENGINE_CLOUD_HOST"); + String port = System.getenv("TDENGINE_CLOUD_PORT"); + String token = System.getenv("TDENGINE_CLOUD_TOKEN"); + String user = System.getenv("TDENGINE_USER_NAME"); + String password = System.getenv("TDENGINE_PASSWORD"); + String jdbcUrl = String.format("jdbc:TAOS-RS://%s:%s?user=%s&password=%s", host, port, user, password); + Properties connProps = new Properties(); + connProps.setProperty(TSDBDriver.PROPERTY_KEY_TOKEN, token); + Connection conn = DriverManager.getConnection(jdbcUrl); + System.out.println("Connected"); + conn.close(); + } +}