TDengine
TDengine copied to clipboard
JCBC connects to the native taosd, which makes Java unable to read the system default time zone
Bug Description 使用JDBC 连接本机taosd 数据库,会使当前java程序无法读取系统默认时区。
To Reproduce
- 连接taosd数据库
- 在程序运行过程中修改系统时区,获取系统时区,java API读取系统时区
Screenshots
Environment (please complete the following information):
- TDengine Version 2.6.0.8
测试代码
public static void main(String[] args) throws SQLException {
Thread thread = new Thread(() -> {
try {
Thread.sleep(4000);
connDB();
changeTime();
} catch (Exception e) {
e.printStackTrace();
}
});
thread.setDaemon(false);
thread.start();
}
public static void connDB() throws SQLException {
DruidDataSource ds = new DruidDataSource();
// jdbc properties
ds.setDriverClassName("com.taosdata.jdbc.TSDBDriver");
ds.setUrl(String.format("jdbc:TAOS://%s:%s", "127.0.0.1", 6030));
ds.setUsername("root");
ds.setPassword("taosdata");
// pool configurations
ds.setInitialSize(10);
ds.setMinIdle(10);
ds.setMaxActive(10);
ds.setMaxWait(30000);
ds.setValidationQuery("select server_status()");
// conn properties
Properties connProps = new Properties();
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")
connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC");
connProps.setProperty("maxSQLLength", String.valueOf(MAX_SQL_LENGTH));
connProps.setProperty("maxBinaryDisplayWidth", "255");
ds.setConnectProperties(connProps);
Connection connection = ds.getConnection(); // get connection
ResultSet set = connection.createStatement().executeQuery("select server_version();");
set.next();
System.out.println("数据库版本:" + set.getString(1));
connection.close();
}
public static void changeTime() throws Exception {
int i = 0;
while (true) {
i++;
System.out.println("\n当前java默认时区:" + TimeZone.getDefault().getID());
//设置时区
String zoned = i % 2 == 0 ? "Asia/Shanghai" : "UTC";
String time = "2022-08-24 00:00:00";
String command = String.format("timedatectl set-timezone \"%s\" && timedatectl set-time \"%s\" && timedatectl | grep zone", zoned, time);
String[] commands = {"/bin/sh", "-c", command};
CmdUtils.Msg msg = CmdUtils.execCmd(3000, StandardCharsets.UTF_8.displayName(), commands);
System.out.println("设置时区命令:" + String.join(" ", commands));
System.out.println("设置后系统时区:" + JSON.toJSONString(msg));
//清空时区,获取默认时区
TimeZone.setDefault(null);
System.getProperties().setProperty("user.timezone", "");
System.out.println("设置后java默认时区:" + TimeZone.getDefault().getID());
Thread.sleep(3000);
}
}
- 请确认在不进行连接 taos 时会不会存在这个问题。
- 尝试在修改时区后,重新启动测试用例。排查 jdk 是否存在缓存。
- 请确认在不进行连接 taos 时会不会存在这个问题。
- 尝试在修改时区后,重新启动测试用例。排查 jdk 是否存在缓存。 0:TimeZone.setDefault(null)`` System.getProperties().setProperty("user.timezone", "")这两行代码,会清空JAVA 默认时区缓存,TimeZone.getDefault() java 会重新获取默认时区 1:上述代码注释conn1:上述代码注释connDB() ,不进行连接时,运行效果复合预期现象如下:
2:重新启动测试用例程序,是正常的但是不是我描述的问题。我分析的原因是程序运行中 如果连接了taos ,会导致java 无法读取默认时区
CmdUtils 是哪个依赖的方法?pom 文件中的依赖 以及 jdk 版本?
CmdUtils 是哪个依赖的方法?pom 文件中的依赖 以及 jdk 版本?
1:CmdUtils 是对Runtime.getRuntime().exec()
的简单封装,你可以替换这个执行本地命令
2:JDK使用的是 :11
3:taos-jdbcdriver 版本为:2.0.39
我测试了下确实如此,但是不是 jdbc 代码原因。在连接 taos server 时出现的问题。 需要找其他人进步一排查。
我测试了下确实如此,但是不是 jdbc 代码原因。在连接 taos server 时出现的问题。 需要找其他人进步一排查。
谢谢。不是JDBC的缘故吗,后续具体原因可以回复一下有点好奇
我测试了下确实如此,但是不是 jdbc 代码原因。在连接 taos server 时出现的问题。 需要找其他人进步一排查。
请问这个BUG ,有计划什么时候进行修复码
2. 代码注释conn1:上述代码注释connDB()
请问这个BUG ,有计划什么时候进行修复码
详见 #18110