TDengine icon indicating copy to clipboard operation
TDengine copied to clipboard

bug of JDBC connector

Open genzo opened this issue 6 years ago • 5 comments

在taos命令行中执行: taos> select id_s,count() from ptuv group by id_s; id_s| count() | id_s|

00360480-3201801002 | 13005|00360480-3201801002
查询结果正常。 其中id_s为 stable ptuv 下子表的tag。

通过JDBC驱动查询: select id_s,count() from ptuv group by id_s; id_s,count(),id_s 0,13005,0 可见TAG id_s的值只剩下首位字母。

genzo avatar Jun 21 '20 05:06 genzo

报一下版本号。

Aries-Lee1991 avatar Jun 21 '20 08:06 Aries-Lee1991

1.6.5.4至1.6.6.0 所有JDBC驱动版本都存在此问题。

genzo avatar Jun 23 '20 08:06 genzo

1.6.5.4至1.6.6.0 所有JDBC驱动版本都存在此问题。

收到,我们这边看一下。

Aries-Lee1991 avatar Jun 24 '20 02:06 Aries-Lee1991

客户端如果在windows环境下均只剩下第一个字符,将客户端迁移至linux端,此问题消失。

sanliang125 avatar Jun 26 '20 11:06 sanliang125

try to use taos-jdbcdriver-2.0.4 and TDengine-2.0.3.0, i have tested your issue and the new jdbc can return the correct result set.

public class TD0751Test {

    private static final String dropdb = "drop database test;";
    private static final String createdb = "create database if not exists test;";
    private static final String usedb = "use test;";

    private static final String createSTable = "create table if not exists ptuv(ts timestamp, f1 int) tags(id_s binary(100));";
    private static final String[] createTable = {
            "create table if not exists d1001 using ptuv tags('00360480-3201801001');",
            "create table if not exists d1002 using ptuv tags('00360480-3201801002');"
    };

    private static final String[] insertTable = {
            "insert into d1001 values('2020-09-06 12:00:00.000', 1);",
            "insert into d1001 values('2020-09-06 12:00:01.000', 2);",
            "insert into d1001 values('2020-09-06 12:00:02.000', 3);",
            "insert into d1002 values('2020-09-06 12:00:03.000', 4);",
            "insert into d1002 values('2020-09-06 12:00:04.000', 5);"
    };


    private static void executeSQL(Connection conn, String sql) throws SQLException {
        Statement stat = null;
        try {
            stat = conn.createStatement();
            boolean execute = stat.execute(sql);
            System.out.println("execut:[" + sql + "] ===> " + execute);
        } finally {
            if (stat != null)
                stat.close();
        }
    }

    public static void main(String[] args) throws Exception {
        Connection conn = getConn();
        executeSQL(conn, dropdb);
        executeSQL(conn, createdb);
        executeSQL(conn, usedb);
        executeSQL(conn, createSTable);
        for (String sql : createTable ){
            executeSQL(conn, sql);
        }
        for (String sql : insertTable) {
            executeSQL(conn, sql);
        }
        executeQuery(conn);
        conn.close();
    }

    private static void executeQuery(Connection conn) throws SQLException {
        Statement stat = conn.createStatement();
        final String sql = "select id_s,count(*) from ptuv group by id_s";
        ResultSet rs = stat.executeQuery(sql);
        ResultSetMetaData metaData = rs.getMetaData();
        int columnCount = metaData.getColumnCount();

        while (rs.next()) {
            for (int i = 1; i <= columnCount; i++) {
                String columnLabel = metaData.getColumnLabel(i);
                System.out.print(columnLabel + " : " + rs.getString(i) + "|\t");
            }
            System.out.println();
        }
        rs.close();
        stat.close();
    }

    public static Connection getConn() throws Exception {
        Class.forName("com.taosdata.jdbc.TSDBDriver");
        String jdbcUrl = "jdbc:TAOS://localhost:6030/log";
        Properties connProps = new Properties();
        connProps.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root");
        connProps.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata");
        connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
        connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
        connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
        Connection conn = DriverManager.getConnection(jdbcUrl, connProps);
        return conn;
    }
}

zyyang90 avatar Sep 06 '20 12:09 zyyang90