project-car/cloud-modules/cloud-modules-template/src/main/java/com/template/util/IOTdbJDBCUtils.java

63 lines
1.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.template.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* @Authorliuxinyue
* @Packagecom.template.util
* @Projectcloud-server
* @nameIOTdbJDBCUtils
* @Date2024/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);
}
}
}
}