提交 a3183dff 编写于 作者: Z zyyang

change

上级 a4fe566c
......@@ -286,7 +286,6 @@ public class JdbcTaosdemo {
executeQuery(sql);
}
private void close() {
try {
if (connection != null) {
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册