package com.chinaztt.mes.basic.util; import java.sql.*; /** * @Author 张宾 * @Date 2023/10/26 */ public class JDBCUtil { private static String url; private static String user; private static String password; private static String driver; static { try { url = "jdbc:postgresql://127.0.0.1:5432/postgres"; user = "postgres"; password = "root2022"; driver = "org.postgresql.Driver"; } catch (Exception e) { e.getMessage(); } } public static Connection getConn() throws Exception { Connection connection = DriverManager.getConnection(url, user, password); return connection; } public static void close(PreparedStatement preparedStatement, Connection connection) { try { if (preparedStatement != null) { preparedStatement.close(); } if (connection != null) { connection.close(); } } catch (SQLException e) { throw new RuntimeException(); } } }