Fixiaobai
2023-11-16 d8d129a2e41f7099968cb4f4dc1b028ab985135f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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();
        }
    }
 
}