TDengine icon indicating copy to clipboard operation
TDengine copied to clipboard

TSDBPreparedStatement issue

Open pujian1984 opened this issue 2 years ago • 2 comments

        StringBuilder sb = new StringBuilder("SELECT utc, mbid, cbjd, cbwd, cbsd, course, csx, rot,fusion_type ");
        sb.append("from ?");
        sb.append(" where utc > ? and utc < ? order by utc desc");
        TSDBPreparedStatement pstmt = (TSDBPreparedStatement) conn.prepareStatement(sb.toString()).unwrap(TSDBPreparedStatement.class);
        pstmt.setTableName("t_0_" + mmsi);
        pstmt.setTimestamp(1, new java.sql.Timestamp(startUtc));
        pstmt.setTimestamp(2, new java.sql.Timestamp(endUtc));
        ResultSet resultSet = pstmt.executeQuery();

以上代码会将第一个Timestamp参数放在表名的参数位置 另外你们的官方文档写的设置参数从0开始,但是实际是从1开始的 微信截图_20220907221435

	<dependency>
	  <groupId>com.taosdata.jdbc</groupId>
	  <artifactId>taos-jdbcdriver</artifactId>
	  <version>3.0.0</version>
	</dependency>

pujian1984 avatar Sep 07 '22 14:09 pujian1984

另外我想咨询一下,预编译对动态表名是否有价值?

pujian1984 avatar Sep 07 '22 14:09 pujian1984

丛 0 开始的,具体可参考:TSDBPreparedStatementTest#executeTest

预编译对 insert 可以批量做插入,加快插入速度。

huolibo avatar Sep 08 '22 06:09 huolibo