diff --git a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTable.java b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTable.java index 49b05850a17b..aa43dcd52c16 100644 --- a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTable.java +++ b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTable.java @@ -135,6 +135,11 @@ public void init() throws InterruptedException { } catch (Exception e) { } } + try { + session.close(); + } catch (IoTDBConnectionException ex) { + // do nothing + } } if (Constants.TSFILE_SUFFIXS.equalsIgnoreCase(fileType)) { ImportTsFileScanTool.setSourceFullPath(targetPath); @@ -179,6 +184,12 @@ protected void importFromSqlFile(File file) { processSuccessFile(); } catch (IOException e) { ioTPrinter.println("SQL file read exception because: " + e.getMessage()); + } finally { + try { + session.close(); + } catch (IoTDBConnectionException ex) { + // do nothing + } } if (!failedRecords.isEmpty()) { FileWriter writer = null; @@ -204,8 +215,8 @@ protected void importFromSqlFile(File file) { protected void importFromTsFile(File file) { final String sql = "load '" + file + "'"; - try { - sessionPool.getSession().executeNonQueryStatement(sql); + try (ITableSession session = sessionPool.getSession()) { + session.executeNonQueryStatement(sql); processSuccessFile(file.getPath()); } catch (final Exception e) { processFailFile(file.getPath(), e); @@ -328,8 +339,8 @@ protected void writeData( } private static void writeAndEmptyDataSet(Tablet tablet, int retryTime) { - try { - sessionPool.getSession().insert(tablet); + try (ITableSession session = sessionPool.getSession()) { + session.insert(tablet); } catch (IoTDBConnectionException e) { if (retryTime > 0) { writeAndEmptyDataSet(tablet, --retryTime);