Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4026488
  • 博文数量: 366
  • 博客积分: 9916
  • 博客等级: 中将
  • 技术积分: 7195
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-29 23:27
个人简介

简单!

文章分类

全部博文(366)

文章存档

2013年(51)

2012年(269)

2011年(46)

分类: Mysql/postgreSQL

2012-11-11 15:56:42

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.

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