java 使用jdbc连接Greenplum数据库和Postgresql数据库
1、公司使用的Greenplum和Postgresql,确实让我学到不少东西。简单将使用jdbc连接Greenplum和Postgresql数据库。由于使用maven仓库,不能下载Greenplum的jar包,但是可以下载Postgresql的jar包,所以Greenplum的jar包,自己可以百度自行下载。名字就叫做greenplum.jar。
maven依赖如下所示:
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.</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.</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-collections/commons-collections -->
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.</version>
</dependency>
2、db.properties配置文件里面如下所示:
# .posgresql
posgresql_driver=org.postgresql.Driver
posgresql_url=jdbc:postgresql://192.168.xx.xx:5432/数据库名称(即schema)
posgresql_user=账号
posgresql_password=密码 # .greenplum
greenplum_driver=com.pivotal.jdbc.GreenplumDriver
greenplum_url=jdbc:pivotal:greenplum://192.168.xx.xx:5432;DatabaseName=数据库名称(即schema)
greenplum_user=账号
greenplum_password=密码
3、然后连接Greenplum数据库和Postgresql数据库如下所示:
public class JdbcUtils { // 1、Postgresql
private static String postgresql_driver;
private static String postgresql_url;
private static String postgresql_user;
private static String postgresql_password; // 2、Greenplum
private static String greenplum_driver;
private static String greenplum_url;
private static String greenplum_user;
private static String greenplum_password; // 1、Postgresql
static {
postgresql_driver = ResourceBundle.getBundle("db").getString("postgresql_driver");
postgresql_url = ResourceBundle.getBundle("db").getString("postgresql_url");
postgresql_user = ResourceBundle.getBundle("db").getString("postgresql_user");
postgresql_password = ResourceBundle.getBundle("db").getString("postgresql_password");
} // 2、Greenplum
static {
greenplum_driver = ResourceBundle.getBundle("db").getString("greenplum_driver");
greenplum_url = ResourceBundle.getBundle("db").getString("greenplum_url");
greenplum_user = ResourceBundle.getBundle("db").getString("greenplum_user");
greenplum_password = ResourceBundle.getBundle("db").getString("greenplum_password");
} // 1、Postgresql
public static Connection getPostgresqlConnection() throws ClassNotFoundException, SQLException {
// 加载数据库驱动
Class.forName(postgresql_driver);
// System.out.println("测试加载数据库成功");
Connection con = DriverManager.getConnection(postgresql_url, postgresql_user, postgresql_password);
// System.out.println("测试数据库链接成功");
return con;
} // 2、Greenplum
public static Connection getGreenplumConnection() throws ClassNotFoundException, SQLException {
// 加载数据库驱动
Class.forName(greenplum_driver);
//System.out.println("测试加载数据库成功");
Connection con = DriverManager.getConnection(greenplum_url, greenplum_user, greenplum_password);
//System.out.println("测试数据库链接成功");
return con;
} public static void main(String[] args) {
try {
JdbcUtils.getPostgresqlConnection();
System.out.println("汇聚数据区连接成功.....");
System.out.println("======================================="); JdbcUtils.getGreenplumConnection();
System.out.println("核心数据区连接成功.....");
System.out.println("======================================="); } catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
4、最后,可以根据公司业务进行一些增删改查操作。略。
待续......
java 使用jdbc连接Greenplum数据库和Postgresql数据库的更多相关文章
- JAVA采用JDBC连接操作数据库详解
JDBC连接数据库概述 一.JDBC基础知识 JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供 ...
- JDBC连接Greenplum数据库,封装了增删改查
要启动好gp服务,再尝试连接 192.168.94.135是主节点(master)的ip 驱动Jar包在官网获取 嫌麻烦,可以直接用我在网盘分享的Jar包,版本较老 链接:https://pan.ba ...
- java用JDBC连接MySQL数据库的详细知识点
想实现java用JDBC连接MySQL数据库.需要有几个准备工作: 1.下载Connector/J的库文件,下载Connector/J的官网地址:http://www.mysql.com/downlo ...
- JAVA通过JDBC连接Oracle数据库详解【转载】
JAVA通过JDBC连接Oracle数据库详解 (2011-03-15 00:10:03) 转载▼http://blog.sina.com.cn/s/blog_61da86dd0100q27w.htm ...
- Java使用JDBC连接SQL Server数据库|实现学生成绩信息系统
Java实验四 JDBC 使用SQL Server数据库或者MySQL数据库各自的客户端工具,完成如下任务: (1)创建数据库students: (2)在数据students中创建表scores,包括 ...
- Java使用JDBC连接SQL Server数据库
Java使用JDBC连接SQL Server数据库 1.下载驱动 1.下载Microsoft SQL Server JDBC 驱动程序 https://docs.microsoft.com/zh-cn ...
- ava基础MySQL存储过程 Java基础 JDBC连接MySQL数据库
1.MySQL存储过程 1.1.什么是存储过程 带有逻辑的sql语句:带有流程控制语句(if while)等等 的sql语句 1.2.存储过程的特点 1)执行效率非常快,存储过程是数据库的服 ...
- JAVA使用jdbc连接MYSQL简单示例
以下展示的为JAVA使用jdbc连接MYSQL简单示例: import java.sql.DriverManager; import java.sql.ResultSet; import java.s ...
- 基于CDH5.x 下面使用eclipse 操作hive 。使用java通过jdbc连接HIVESERVICE 创建表
基于CDH5.x 下面使用eclipse 操作hive .使用java通过jdbc连接HIVESERVICE 创建表 import java.sql.Connection; import java.s ...
随机推荐
- Linker Scripts3--简单的链接脚本命令1
1.前言 这个部分我们描述了简单的链接脚本命令 2.设置entry point 程序中第一条运行的指令被称为入口点entry point,可以使用ENTRY链接脚本命令设置entry point,参数 ...
- fabric.js PatternBrush
// Original canvas const canvas = new fabric.Canvas('canvas'); fabric.Image.fromURL('https://picsum. ...
- InstallShield 静默安装
可能先需要获取安装包参数,安装包参数获取/?或是/HELP InstallScrip工程 1. 在命令行窗口中使用 -R 参数(即record) 运行安装程序. 例如: Setup.exe -R or ...
- Java序列化Serializable
1.什么是序列化和反序列化 Serialization(序列化)是一种将对象以一连串的字节描述的过程:deserialization(反序列化)是一种将这些字节重建成一个对象的过程. 2.什么情况下需 ...
- This Product is covered by one or more of the following......的问题
DELL台式机安装ubuntu后无法正常启动,黑屏显示:This Product is covered by one or more of the following...... 解决方案:进入BIO ...
- hibernate框架学习之持久化对象OID
持久化对象唯一标识——OID 1)数据库中使用主键可以区分两个对象是否相同2)Java语言中使用对象的内存地址区分对象是否相同3)Hibernate中使用OID区分对象是否相同Hibernate认为每 ...
- CROSS APPLY和 OUTER APPLY
背景 好强大的sql,但是我好想真极少用过这两个函数,再次强调,不要总是用sql解决问题.让人欢喜让人悲的sql. -- cross applyselect * from TABLE_1 T1cr ...
- Razor视图基本语法
<!--Razor C#--> @for (int i = 0; i < 10; i++) { <baobao>good</baobao> } < ...
- how to get address of member function
see:http://www.cplusplus.com/forum/general/136410/ & http://stackoverflow.com/questions/8121320/ ...
- Codeforces 993E Nikita and Order Statistics [FFT]
洛谷 Codeforces 思路 一开始想偏想到了DP,后来发现我SB了-- 考虑每个\(a_i<x\)的\(i\),记录它前一个和后一个到它的距离为\(L_i,R_i\),那么就有 \[ an ...