dev
parent
bef61a5d29
commit
d53193eb4b
|
@ -6,6 +6,7 @@ import com.template.service.CarService;
|
|||
import com.template.service.MessageTemplateTypeService;
|
||||
import com.template.service.TemplateService;
|
||||
import com.template.util.ToIoTDB;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||
import org.apache.iotdb.session.Session;
|
||||
|
@ -25,6 +26,7 @@ import java.util.List;
|
|||
* @name:TemplateServiceImp
|
||||
* @Date:2024/9/20 12:12
|
||||
*/
|
||||
@Log4j2
|
||||
@Service
|
||||
public class TemplateServiceImpl implements TemplateService{
|
||||
|
||||
|
@ -62,7 +64,7 @@ public class TemplateServiceImpl implements TemplateService{
|
|||
}
|
||||
//取出VIN码
|
||||
String carVin = result.substring(0, 18-1);
|
||||
System.out.println("carVin码为:"+carVin);
|
||||
log.info("carVin码为:"+carVin);
|
||||
//根据VIN码获取车辆信息
|
||||
SysCar carByVin = carService.findCarByVin(carVin);
|
||||
if(carByVin==null){
|
||||
|
@ -84,7 +86,8 @@ public class TemplateServiceImpl implements TemplateService{
|
|||
jsonObject.put(messageTemplateType.getMessageField(), result.substring(startIndex, endIndex-1));
|
||||
}
|
||||
|
||||
System.out.println("解析后的报文是:"+jsonObject);
|
||||
log.info("解析后的报文是:"+jsonObject);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +107,7 @@ public class TemplateServiceImpl implements TemplateService{
|
|||
//开启Session RPC不压缩
|
||||
session.open(false);
|
||||
session.open(false);
|
||||
System.out.println("写入数据");
|
||||
log.info("写入数据");
|
||||
//写入数据
|
||||
List<Object> values = new ArrayList<>();
|
||||
values.add(jsonObject);
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package com.template.util;
|
||||
import java.sql.Connection;
|
||||
/**
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.template.util
|
||||
* @Project:cloud-server
|
||||
* @name:IOTDBConnectionTets
|
||||
* @Date:2024/9/24 10:34
|
||||
*/
|
||||
public class IOTDBConnectionTets {
|
||||
|
||||
private static final String url = "jdbc:iotdb://47.116.173.119:6667/";
|
||||
private static final String username = "root";
|
||||
private static final String password = "root";
|
||||
|
||||
public static void main(String[] args) {
|
||||
Connection conn = new IOTdbJDBCUtils(url, username, password).getConnection();
|
||||
System.out.println(conn != null ? "打开连接成功!" : "打开连接失败!");
|
||||
IOTdbJDBCUtils.close(conn);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package com.template.util;
|
||||
|
||||
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.template.util
|
||||
* @Project:cloud-server
|
||||
* @name:IOTdbJDBCUtils
|
||||
* @Date:2024/9/24 10:18
|
||||
*/
|
||||
public class IOTdbJDBCUtils {
|
||||
private static final String driver = "org.apache.iotdb.jdbc.IoTDBDriver";
|
||||
private final String url;
|
||||
private final String username;
|
||||
private final String password;
|
||||
|
||||
public IOTdbJDBCUtils(String url, String username, String password) {
|
||||
this.url = url;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName(driver);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
System.out.println("当前加载的驱动不存在........,请检查后重试!");
|
||||
}
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
Connection connection = null;
|
||||
try {
|
||||
connection = DriverManager.getConnection(url, username, password);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
public static void close(Connection conn) {
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.template.util;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.template.util
|
||||
* @Project:cloud-server
|
||||
* @name:ToIoTDBTest
|
||||
* @Date:2024/9/24 10:12
|
||||
*/
|
||||
public class ToIoTDBTest {
|
||||
|
||||
private static final String host = "47.116.173.119";
|
||||
private static final String url = "jdbc:iotdb://" + host + ":6667/";
|
||||
private static final String username = "root";
|
||||
private static final String password = "root";
|
||||
|
||||
|
||||
public static void main(String[] args) throws SQLException, ClassNotFoundException {
|
||||
|
||||
ToIoTDB toIoTDB = new ToIoTDB();
|
||||
Connection connection = toIoTDB.getConnection();
|
||||
// Connection connection = (Connection) new IOTdbJDBCUtils(url, username, password).getConnection();
|
||||
System.out.println(connection!=null?"打开连接成功!":"打开连接失败!");
|
||||
|
||||
ResultSet rs=null;
|
||||
String storgeGroup="root.test";
|
||||
Statement statement = connection.createStatement();
|
||||
String sql=String.format("set storage group to %s",storgeGroup);
|
||||
statement = connection.createStatement();
|
||||
int i = statement.executeUpdate(sql);
|
||||
System.out.println("当前创建组的结果为:"+i);
|
||||
|
||||
//查看创建的组是否存在
|
||||
sql="SHOW STORAGE GROUPS"; //查看所有的存储组
|
||||
rs= statement.executeQuery(sql);
|
||||
outputResult(rs);
|
||||
|
||||
sql=String.format("show storage group %s",storgeGroup);
|
||||
rs=statement.executeQuery(sql);
|
||||
outputResult(rs);
|
||||
//统计存在的数量
|
||||
sql=String.format("count storage group %s",storgeGroup);
|
||||
rs=statement.executeQuery(sql);
|
||||
outputResult(rs);
|
||||
}
|
||||
|
||||
private static void outputResult(ResultSet resultSet) throws SQLException {
|
||||
if (resultSet != null) {
|
||||
System.out.println("--------------------------");
|
||||
final ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
final int columnCount = metaData.getColumnCount();
|
||||
for (int i = 0; i < columnCount; i++) {
|
||||
System.out.print(metaData.getColumnLabel(i + 1) + ", ");
|
||||
}
|
||||
System.out.println();
|
||||
while (resultSet.next()) {
|
||||
for (int i = 1;; i++) {
|
||||
System.out.print(resultSet.getString(i));
|
||||
if (i < columnCount) {
|
||||
System.out.print(", ");
|
||||
} else {
|
||||
System.out.println();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("--------------------------\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue