Greenplum数据库连接

Greenplum数据库连接

image-20210225104242551

maven配置

<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql --> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>42.1.4</version> </dependency> <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils --> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>1.9.3</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.4</version> </dependency> <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging --> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> </dependency> <!-- https://mvnrepository.com/artifact/commons-collections/commons-collections --> <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://192.168.xx.xx:5432/数据库名称(即schema) posgresql_user=账号 posgresql_password=密码 # 2.greenplum greenplum_driver=com.pivotal.jdbc.GreenplumDriver greenplum_url=jdbc:pivotal:greenplum://192.168.xx.xx:5432;DatabaseName=数据库名称(即schema) greenplum_user=账号 greenplum_password=密码

连接Greenplum数据库和Postgresql数据库如下所示:

1 public class JdbcUtils { 2 3 // 1、Postgresql 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 // 2、Greenplum 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 // 1、Postgresql 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 // 2、Greenplum 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 // 1、Postgresql 33 public static Connection getPostgresqlConnection() throws ClassNotFoundException, SQLException { 34 // 加载数据库驱动 35 Class.forName(postgresql_driver); 36 // System.out.println("测试加载数据库成功"); 37 Connection con = DriverManager.getConnection(postgresql_url, postgresql_user, postgresql_password); 38 // System.out.println("测试数据库链接成功"); 39 return con; 40 } 41 42 // 2、Greenplum 43 public static Connection getGreenplumConnection() throws ClassNotFoundException, SQLException { 44 // 加载数据库驱动 45 Class.forName(greenplum_driver); 46 //System.out.println("测试加载数据库成功"); 47 Connection con = DriverManager.getConnection(greenplum_url, greenplum_user, greenplum_password); 48 //System.out.println("测试数据库链接成功"); 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 }

__EOF__

本文作者JessePinkMan
本文链接https://www.cnblogs.com/edclol/p/17282472.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   edclol  阅读(202)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示