一、 连接
public Connection getRestConn() throws Exception{
Class.forName(“com.taosdata.jdbc.rs.RestfulDriver”);
String jdbcUrl = “jdbc:TAOS-RS://(你的IP加端口或域名)/(数据库名称)? user=user&password=passwordt”;
Properties connProps = new Properties();
connProps.setProperty(TSDBDriver.PROPERTY_KEY_BATCH_LOAD, “true”);
// connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, “Asia/Shanghai”);
Connection conn = DriverManager.getConnection(jdbcUrl, connProps);
return conn;
}
二、查询
ResultSet resultSet = stmt.executeQuery(“SELECT * FROM meters”);
Timestamp ts;
float current;
String location;
while(resultSet.next()){
// 查出的数据库字段名直接取
ts = resultSet.getTimestamp(1);
current = resultSet.getFloat(2);
location = resultSet.getString(“location”);
System.out.printf(“%s, %f, %s\n”, ts, current, location);
}