Chinaunix首页 | 论坛 | 博客
  • 博客访问: 291532
  • 博文数量: 186
  • 博客积分: 1531
  • 博客等级: 上尉
  • 技术积分: 1275
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-06 16:56
文章分类

全部博文(186)

文章存档

2013年(2)

2012年(184)

分类:

2012-11-13 15:15:26

原文地址:PostgreSQL简介 作者:txgc_wm

JDBC

JDBC is an API for the Java programming language that defines how a client may access a database. It provides methods for querying and updating data in a database. JDBC is oriented towards relational databases. From a technical point of view, the API is as a set of classes in the java.sql package. To use JDBC with a particular database, we need a JDBC driver for that database.



About PostgreSQL database

PostgreSQL is a powerful, open source object-relational database system. It is a multi-user, multi-threaded database management system. It runs on multiple platforms including Linux, FreeBSD, Solaris, Microsoft Windows and Mac OS X. PostgreSQL is developed by the PostgreSQL Global Development Group.



Before we start

We need to install postgresql package. We need to install the JDK, Java Development Kit, for compiling and running Java programs. Finally, we need the PostgreSQL Java driver. If we are using Netbeans IDE, than we have already the driver at hand. Inside the Projects tab, right click on the Libraries node and select Add Library option. From the list of options, select PostgreSQL JDBC Driver. Note that the driver may be older. Older driver may cause problems on newer PostgreSQL versions. In such a case, we can add the newest driver from by choosing add JAR/Folder and selecting a driver from the filesystem.


Netbeans project libs
Figure: Netbeans project libs

If we want to compile the examples from the command line, go to the site and download the latest PostgreSQL Java Driver.

$ javac zetcode/Version.java
$ java -cp .:lib/postgresql.jdbc4.jar zetcode/Version
PostgreSQL 9.1.2 on i686-pc-linux-gnu, compiled by gcc-4.6.real (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1, 32-bit

Assuming, that we have put the driver jar file into the lib directory and using package zetcode, we compile and run the first example this way.

阅读(465) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~