首页 > 数据库 >Greenplum数据库连接

Greenplum数据库连接

时间:2023-04-03 11:14:38浏览次数:42  
标签:postgresql 连接 greenplum driver 数据库 static user password 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 }        

标签:postgresql,连接,greenplum,driver,数据库,static,user,password,Greenplum
From: https://www.cnblogs.com/edclol/p/17282472.html

相关文章

  • GreenPlum安装
    GreenPlum安装指南针对Centos7平台[gpadmin@aivmp-bigdata0001~]$cat/etc/centos-releaseCentOSLinuxrelease7.6.1810(Core)机器外网地址121.36.194.125aivmp-bigdata0001124.70.139.178aivmp-bigdata0002124.70.192.187aivmp-bigdata0003121.36.245.248e......
  • 【测试】主流数据库存储过程编写样例(Oracle、MySQL、SQL Server)
    这个...做测试其实有时候还是需要先弄点数据才好针对某些功能进行测试的(相信做过开发的都应该深有体会)。一般像我这种老油条都推荐使用存储过程来做的初始化数据,一来脚本不会骗人,二来可以通过另一种方式验证逻辑关系。下面将整理了三个主流数据库(Oracle、MySQL和SQLServer)的“单表......
  • Mybatis之数据库连接+PageHelper分页插件+Mybatis-Plus插件
    MyBatisPlus教程(人人便成为)https://www.cnblogs.com/chch213/p/16320820.html前言ORM框架:对象关系映射 objectrelationalmapping 半自动ORM映射工具(自己编写sql语句)  Hibernater属于全自动映射规则:数据库表>类|表字段>类的属性|表数据>对象 JDBC操......
  • 若分离HTML与CSS,要记得连接外部CSS文件
    使用下列代码即可连接,注意CSS文件名和HTML文件名相同:<linkrel="stylesheet"type="text/css"href="文件名.css">  应放在代码头,如下所示:<!DOCTYPEhtml><htmllang="en"><head>  <metacharset="UTF-8">  &......
  • Python3连接MySQL
    一、安装引入pymysql模块1、安装pipinstallPyMySQL2、Pycharm中引入pymysql3、在文件中引入模块importpymysql如果系统不支持pip命令,可以使用git命令下载安装包安装(也可以手动下载):$gitclonehttps://github.com/PyMySQL/PyMySQL$cdPyMySQL/$python3setup.pyinsta......
  • 1.内连接
    一,内连接A.特点:通过表之间共有的属性来连接,会丢失不匹配的数据,例如下面两个表中,只会保留两个表中属性institute_id的值为1的数据B.语法:#假设A有ab属性,B有bc属性,b是它们共有的属性SELECTa,b,cFROMAJOINBONA.b=B.b;##语法解读:#SELECTa,b,c选中abc属性#......
  • Django使用数据库
    一、数据库配置使用前要设置时区TIME_ZONE,TIME_ZONE='UTC'还要注意setting.py配置文件头部的INSTALLED_APPS选项(已安装程序)。确认自建的pollsapp应用已经安装到总项目容器中了。就是添加一句话:‘pollsapp.apps.PollsappConfig’,其中pollsapp是你创建应用的名字,apps表示应......
  • Day 20 20.2 数据库之MySQL基础
    基本概念前面的学习中我们提到,mysql是关系型数据库,所以我们要操作mysql就需要使用SQL(结构化查询语言)。SQL规范1.在数据库管理系统中,SQL语句关键字不区分大小写(但建议用大写),参数区分大小写。建议命令大写,数据库名、数据表名、字段名统一小写,如数据库名、数据表名、字......
  • Day 20 20.3 数据库之Python操作MySQL
    Python操作MySQLimportpymysql#打开数据库连接db=pymysql.connect(host='localhost',user='root',passwd='...',port=3306,datebase='...')print('连接成功!')#使用cursor()方法创建一个游标对象cursorcursor=db.cursor()#......
  • Day 21 21.1 数据库之redis
    Redisredis介绍定义Redis(RemoteDictionaryServer,远程字典服务)是一个使用ANSIC编写的开源、支持网络、基于内存、可选持久性的键值对存储数据库,是NoSQL数据库。redis的出现主要是为了替代早期的Memcache缓存系统的。map内存型(数据存放在内存中)的非关系型(nosql)key-......