JDBC访问GreenPlum
来源:互联网 发布:centos 安装配置ftp 编辑:程序博客网 时间:2024/06/15 01:03
JDBC is the driver used to access a database with Java. Greenplum has a full working JDBC implementation.
In this short article we’ll see how to use it.
## Download and install
It is possible to download the JDBC for Greenplum directly from the Greenplum Community Edition site (http://www.greenplum.com/community/downloads/database-ce/).
Look for the *”Connectivity Tools”* file.
You will receive a link to download the archive file.
Extract the archive and run the binary extracted. Then follow the instructions on screen and in less than a minute you have installed JDBC.
## Prepare the Greenplum server
After a successful installation, make sure that the server accepts TCP connections from the desired hosts. Check that *listen_addresses* is properly set in postgresql.conf.
**Note:** by default, Greenplum listens to any address.
Another aspect you have to consider is the user authentication, which is delegated to the pg_hba.conf file (please refer to page 36 of Greenplum AdminGuide for more information).
After you have verified the user is able to connect to the database, you can go on and test JDBC.
Connecting to a Greenplum Database with JDBC is a three steps procedure:
* Import JDBC
* Load the driver
* Connect to the database
Remember that the *forName* function can throw a *ClassNotFoundException* if the driver is not available. We do not try to catch that exception in the simple example below. You should in your production environment.
To connect to a database using JDBC, you have to use a connection URL. It can be in one of these three forms:
* jdbc:postgresql:databasename
* jdbc:postgresql://host/databasename
* jdbc:postgresql://host:port/databasename
Build an URL that suits your needs and use it with the getConnection function. For example:
package com.gp.dbtest;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class GPDBTest {public static void main(String[] args) {try {Class.forName("org.postgresql.Driver");Connection db = DriverManager.getConnection("jdbc:postgresql://192.168.1.23:5432/zwcdb","zhongwc","zhongwc");Statement st = db.createStatement();ResultSet rs = st.executeQuery("select * from tab_gp limit 1 offset 0");while (rs.next()) {System.out.println(rs.getString(1));}rs.close();st.close();} catch (ClassNotFoundException e) {e.printStackTrace();} catch (SQLException e) {e.printStackTrace();}}}
- JDBC访问GreenPlum
- jdbc连接greenplum
- 客户端如何访问greenplum
- Oracle通过DBLINK访问GreenPlum
- java 使用jdbc连接Greenplum数据库
- Perl脚本访问Greenplum数据库安装指导
- Python脚本访问Greenplum数据库安装指导
- Python脚本访问Greenplum数据库安装指导
- greenplum通过hdfs访问外部表
- Greenplum
- greenplum
- greenplum
- GreenPlum
- greenplum
- JDBC-ODBC访问数据库,JDBC访问数据库
- 使用jdbc访问数据库
- Java JDBC访问MySql
- JDBC访问DB2
- 华为面试题解析 - 09
- 坚持
- 四、java流程控制(二)-分支控制
- 黑马程序员 Java String 类
- 基于ArrayCollection的flex tree
- JDBC访问GreenPlum
- 柱状图,曲线图显示数据结点
- [深入浅出Cocoa]iOS网络编程之NSStream
- Objective-C语法之NSSet和NSMutableSet
- C指针原理 (26)-C指针基础
- 今天遇到小偷了!!!快过年了,大家都注意一点
- POJ 1251 Jungle Roads (zoj 1406) MST
- [深入浅出Cocoa]iOS网络编程之CFNetwork
- tomcat 端口冲突问题的解决办法