|
package com; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class TestJDBC { private Connection con ; private String user = "gpadmin" ; private String password = "123456" ; private String className = "com.pivotal.jdbc.GreenplumDriver " ; private String url = "jdbc:pivotal:greenplum://172.20.4.161:5432;DatabaseName=testDB" ; public static void main(String[] args) { // TODO Auto-generated method stub TestJDBC c = new TestJDBC(); c.Connect(); c.getCon(); c.closed(); } public void Connect() { try { Class. forName(className); System. out.println("加载数据库驱动成功!" ); } catch (ClassNotFoundException e ) { System. out.println("加载数据库驱动失败!" ); e.printStackTrace(); } } /** 创建数据库连接 */ public Connection getCon() { try { con = DriverManager. getConnection(url, user, password); System. out.println("创建数据库连接成功!" ); } catch (SQLException e ) { System. out.print(con ); System. out.println("创建数据库连接失败!" ); con = null; e.printStackTrace(); } return con ; } public void closed() { try { if (con != null) { con.close(); } } catch (SQLException e ) { System. out.println("关闭con对象失败!" ); e.printStackTrace(); } } } . L% O' L( e9 d% r9 s* P
& s6 n: p. a3 @% \* ` ^$ e9 w4 [1 R/ z9 B; h, l
. ~& u+ o9 t7 V( L
1 d- L1 L+ a( D. I) S B# w) @+ G1 n
: d }: H0 m4 ^ b) W2 i6 X% P
9 ^! J0 e! c0 }2 ~ k
1 S; p% ?. u, V" r' Y资源下载地址和密码(百度云盘): [/hide] 百度网盘信息回帖可见4 v- W* c" e0 A4 a7 X# i* y
. Z9 H( w `- u* Q% i
4 w3 [$ D* Q" J. i6 i
% y T Y1 k3 E% n( E9 _* l Q本资源由Java自学网收集整理【www.javazx.com】 |
|