command.txt 1.3 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
# Linux Platform
install.packages('rJDBC', repos='http://cran.us.r-project.org')

# Loading RJDBC packages
library('RJDBC')
# Set up working path and JDBC driver storage location
setwd('C:/TDengine')

# Load JDBC Driver for TDengine
drv<-JDBC("com.taosdata.jdbc.TSDBDriver","JDBCDriver-1.0.0-dist.jar", identifier.quote="\"")

# Connect to the database
conn<-dbConnect(drv,"jdbc:TSDB://192.168.1.114:0/?user=root&password=taosdata","root","taosdata")

# Get connection information
dbGetInfo(conn)

# Using database test
dbSendUpdate(conn, "use test")

# Insert data
dbSendUpdate(conn, "insert into t1 values(now, 99)")

# View all tables
table1<-dbGetQuery(conn,"show tables") 

# Functional support for RJDBC

# List all tables
dbListTables(conn)

# Is there table iris
dbExistsTable(conn,”iris”)

# Connect summary information
summary(conn)
dbGetInfo(conn)

# Read all the data from the T1 table
dbReadTable(conn, "t1")

# Delete table t1
dbRemoveTable(conn,"t1")

# Execute any non-query SQL statements
dbSendUpdate(conn, "create table t1(a timestamp, b int, c nchar(12))");

# Write data
dbWriteTable(conn, "t1", t_demo_n, overwrite=FALSE, append=TRUE)

# Extracting data on demand using SQL statements
dbGetQuery(conn, "select k from tu")

# Close the connection
dbDisconnect(conn)