This commit is contained in:
zyyang 2020-12-14 22:06:12 +08:00
parent a4fe566cf6
commit a3183dff36
2 changed files with 41 additions and 2 deletions

View File

@ -286,7 +286,6 @@ public class JdbcTaosdemo {
executeQuery(sql);
}
private void close() {
try {
if (connection != null) {

View File

@ -5,9 +5,15 @@ import com.taosdata.taosdemo.domain.SubTableValue;
import com.taosdata.taosdemo.domain.SuperTableMeta;
import com.taosdata.taosdemo.mapper.SubTableMapper;
import com.taosdata.taosdemo.service.data.SubTableMetaGenerator;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
@ -18,6 +24,8 @@ import java.util.concurrent.TimeUnit;
@Service
public class SubTableService extends AbstractService {
private static Logger logger = Logger.getLogger(SubTableService.class);
@Autowired
private SubTableMapper mapper;
@ -99,11 +107,43 @@ public class SubTableService extends AbstractService {
return mapper.insertOneTableMultiValuesUsingSuperTable(subTableValue);
}
@Autowired
private SqlSessionFactory sqlSessionFactory;
@Autowired
private DataSource dataSource;
// 插入多表自动建表, insert into xxx using XXX tags(...) values(),()... xxx using XXX tags(...) values(),()...
public int insertAutoCreateTable(List<SubTableValue> subTableValues) {
return mapper.insertMultiTableMultiValuesUsingSuperTable(subTableValues);
Connection connection = null;
Statement statement = null;
int affectRows = 0;
try {
connection = dataSource.getConnection();
String sql = sqlSessionFactory.getConfiguration()
.getMappedStatement("com.taosdata.taosdemo.mapper.SubTableMapper.insertMultiTableMultiValuesUsingSuperTable")
.getBoundSql(subTableValues)
.getSql();
logger.info(">>> SQL : " + sql);
// statement = connection.createStatement();
// affectRows = statement.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return affectRows;
}
// return mapper.insertMultiTableMultiValuesUsingSuperTable(subTableValues);
private static void sleep(int sleep) {
if (sleep <= 0)
return;