Greenplum数据库连接

maven配置
<!-- https:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.4</version>
</dependency>
<!-- https:
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
<!-- https:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<!-- https:
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https:
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
db.properties
# 1.posgresql
posgresql_driver=org.postgresql.Driver
posgresql_url=jdbc:postgresql:
posgresql_user=账号
posgresql_password=密码
# 2.greenplum
greenplum_driver=com.pivotal.jdbc.GreenplumDriver
greenplum_url=jdbc:pivotal:greenplum:
greenplum_user=账号
greenplum_password=密码
连接Greenplum数据库和Postgresql数据库如下所示:
1 public class JdbcUtils {
2
3
4 private static String postgresql_driver;
5 private static String postgresql_url;
6 private static String postgresql_user;
7 private static String postgresql_password;
8
9
10 private static String greenplum_driver;
11 private static String greenplum_url;
12 private static String greenplum_user;
13 private static String greenplum_password;
14
15
16 static {
17 postgresql_driver = ResourceBundle.getBundle("db").getString("postgresql_driver");
18 postgresql_url = ResourceBundle.getBundle("db").getString("postgresql_url");
19 postgresql_user = ResourceBundle.getBundle("db").getString("postgresql_user");
20 postgresql_password = ResourceBundle.getBundle("db").getString("postgresql_password");
21 }
22
23
24 static {
25 greenplum_driver = ResourceBundle.getBundle("db").getString("greenplum_driver");
26 greenplum_url = ResourceBundle.getBundle("db").getString("greenplum_url");
27 greenplum_user = ResourceBundle.getBundle("db").getString("greenplum_user");
28 greenplum_password = ResourceBundle.getBundle("db").getString("greenplum_password");
29 }
30
31
32
33 public static Connection getPostgresqlConnection() throws ClassNotFoundException, SQLException {
34
35 Class.forName(postgresql_driver);
36
37 Connection con = DriverManager.getConnection(postgresql_url, postgresql_user, postgresql_password);
38
39 return con;
40 }
41
42
43 public static Connection getGreenplumConnection() throws ClassNotFoundException, SQLException {
44
45 Class.forName(greenplum_driver);
46
47 Connection con = DriverManager.getConnection(greenplum_url, greenplum_user, greenplum_password);
48
49 return con;
50 }
51
52 public static void main(String[] args) {
53 try {
54 JdbcUtils.getPostgresqlConnection();
55 System.out.println("汇聚数据区连接成功.....");
56 System.out.println("=======================================");
57
58 JdbcUtils.getGreenplumConnection();
59 System.out.println("核心数据区连接成功.....");
60 System.out.println("=======================================");
61
62 } catch (ClassNotFoundException e) {
63 e.printStackTrace();
64 } catch (SQLException e) {
65 e.printStackTrace();
66 }
67 }
68 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人