37 lines
1.1 KiB
Java
37 lines
1.1 KiB
Java
package com.template.util;
|
||
import lombok.extern.log4j.Log4j2;
|
||
import org.springframework.context.annotation.Configuration;
|
||
import java.sql.Connection;
|
||
import java.sql.DriverManager;
|
||
import java.sql.SQLException;
|
||
/**
|
||
* @Author:liuxinyue
|
||
* @Package:com.template.util
|
||
* @Project:cloud-server
|
||
* @name:ToIoTDB 连接IoTDB数据库
|
||
* @Date:2024/9/20 19:40
|
||
*/
|
||
@Log4j2
|
||
@Configuration
|
||
public class ToIoTDB {
|
||
|
||
private final String IOTDB_DRIVER="org.apache.iotdb.jdbc.IoTDBDriver";
|
||
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 Connection getConnection() throws ClassNotFoundException, SQLException {
|
||
Connection connection=null;
|
||
try{
|
||
Class.forName(IOTDB_DRIVER);
|
||
connection = DriverManager.getConnection(url, userName, passWord);
|
||
}catch(SQLException e){
|
||
log.error("SQLException: " + e.getMessage());
|
||
log.error("SQLState: " + e.getSQLState());
|
||
log.error("VendorError: " + e.getErrorCode());
|
||
}
|
||
return connection;
|
||
}
|
||
|
||
}
|