diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java index b91fe88dfacd7c6e414aa842184b2c349b3e33b9..2ff0d86c920aa0aae67f71448bf9112564293350 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java @@ -19,6 +19,7 @@ import com.taosdata.jdbc.utils.NullType; import java.math.BigDecimal; import java.sql.SQLException; import java.sql.Timestamp; +import java.time.Instant; import java.util.ArrayList; import java.util.Collections; @@ -463,6 +464,25 @@ public class TSDBResultSetRowData { data.set(col, tsObj); } + /** + * this implementation is used for TDengine old version + */ + public void setTimestamp(int col, long ts) { + //TODO: this implementation contains logical error + // when precision is us the (long ts) is 16 digital number + // when precision is ms, the (long ts) is 13 digital number + // we need a JNI function like this: + // public void setTimestamp(int col, long epochSecond, long nanoAdjustment) + if (ts < 1_0000_0000_0000_0L) { + data.set(col, new Timestamp(ts)); + } else { + long epochSec = ts / 1000_000L; + long nanoAdjustment = ts % 1000_000L * 1000L; + Timestamp timestamp = Timestamp.from(Instant.ofEpochSecond(epochSec, nanoAdjustment)); + data.set(col, timestamp); + } + } + public Timestamp getTimestamp(int col, int nativeType) { Object obj = data.get(col - 1); if (obj == null)