Skip to content

stmt2 无法在select where 条件中使用参数化查询 #35433

Description

@YYQHoro

Bug Description

stmt2 无法在select where 条件中使用参数化查询

  1. 版本:
    Docker 部署于Ubuntu24.04,tdengine/tsdb:3.4.1.6、tdengine/tsdb:3.4.2.2 版本均有此问题

  2. 客户端:

    com.taosdata.jdbc
    taos-jdbcdriver
    3.9.0

To Reproduce

  1. test是一个超级表。
        String jdbcUrl = "jdbc:TAOS-WS://localhost:6041/device_dev?varcharAsString=true";
        Properties props = new Properties();
        props.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root");
        props.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "123456");

        String sql = "SELECT t.tbname t.rssi FROM test t WHERE t.rssi = ?";
        try (Connection conn = DriverManager.getConnection(jdbcUrl, props);
             TSWSPreparedStatement ps = conn.prepareStatement(sql).unwrap(TSWSPreparedStatement.class)) {

            ps.setLong(1, 1);
            System.out.println("执行SQL:" + sql);
            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {

                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
            Assertions.fail(e.getMessage());
        }

报错:

java.sql.SQLException: (0x2600):stmt only support 'SELECT' or 'INSERT'
	at com.taosdata.jdbc.utils.StmtUtils.initStmtWithRetry(StmtUtils.java:38)
	at com.taosdata.jdbc.ws.WSConnection.prepareStatement(WSConnection.java:88)
        ...

删除 where t.rssi = ? 后执行正常。

Expected Behavior
希望能支持在where条件中支持参数化查询

Screenshots

Image Image

Environment (please complete the following information):

  • OS: Windows 11
  • JDK:corretto-17.0.16
  • TDengine Version:Docker tdengine/tsdb:3.4.1.6、tdengine/tsdb:3.4.2.2
  • taos-jdbcdriver: 3.8.3、3.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions