TDengine icon indicating copy to clipboard operation
TDengine copied to clipboard

【求助 】使用 schemaless 写入超级表 运行SchemalessWsTest.java报错

Open JJiacheng opened this issue 1 year ago • 2 comments

具体报错信息如下: [WebSocketConnectReadThread-12] DEBUG com.taosdata.jdbc.ws.WSClient - disconnect uri: ws://127.0.0.1:6041/ws, code : 1002 , reason: Invalid status code received: 404 Status line: HTTP/1.1 404 Not Found, remote: false Exception in thread "main" java.sql.SQLException: ERROR (0x231d): can't create connection with server within: 60000 milliseconds

本地docker 搭建的 tdengine 版本号3.1.1.0

taos-jdbcdriver版本 3.2.11

JJiacheng avatar Jun 13 '24 09:06 JJiacheng

package com.alibaba.datax.plugin.writer.tdengine30writer;

import com.taosdata.jdbc.AbstractConnection; import com.taosdata.jdbc.SchemalessWriter; import com.taosdata.jdbc.enums.SchemalessProtocolType; import com.taosdata.jdbc.enums.SchemalessTimestampType;

import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement;

// ANCHOR: schemaless public class LineProtocolExample { private static final String host = "127.0.0.1"; private static final String lineDemo = "meters,groupid=2,location=California.SanFrancisco current=10.3000002f64,voltage=219i32,phase=0.31f64 1626006833639000000"; private static final String telnetDemo = "stb0_0 1707095283260 4 host=host0 interface=eth0"; private static final String jsonDemo = "{"metric": "meter_current","timestamp": 1626846400,"value": 10.3, "tags": {"groupid": 2, "location": "California.SanFrancisco", "id": "d1001"}}";

public static void main(String[] args) throws SQLException {
    final String url = "jdbc:TAOS-RS://" + host + ":6041/power?user=root&password=taosdata&batchfetch=true";
    try(Connection connection = DriverManager.getConnection(url)){
        init(connection);
        SchemalessWriter writer = new SchemalessWriter(connection);

        writer.write(lineDemo, SchemalessProtocolType.LINE, SchemalessTimestampType.NANO_SECONDS);
        writer.write(telnetDemo, SchemalessProtocolType.TELNET, SchemalessTimestampType.MILLI_SECONDS);
        writer.write(jsonDemo, SchemalessProtocolType.JSON, SchemalessTimestampType.SECONDS);
    }
}

private static void init(Connection connection) throws SQLException {
    try (Statement stmt = connection.createStatement()) {
        stmt.execute("CREATE DATABASE IF NOT EXISTS power");
        stmt.execute("USE power");
    }
}

} // ANCHOR_END: schemaless

JJiacheng avatar Jun 13 '24 09:06 JJiacheng

image tdengine 版本3.1.1.0直接用REST 连接batchfetch 参数并设置为 true,开启 WebSocket 连接 不支持吧

JJiacheng avatar Jun 13 '24 12:06 JJiacheng

支持的。不过这个版本还是比较旧,一年多前了。可以更新到最新的3.3.3.0数据库和最新的驱动版本,还有问题可以联系微信a15652223354

yu285 avatar Oct 12 '24 03:10 yu285