Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 86b8bd0

Browse files
author
Peter Mount
committed
Minor fixes ready for 7.0
1 parent c804a48 commit 86b8bd0

File tree

6 files changed

+153
-72
lines changed

6 files changed

+153
-72
lines changed

src/interfaces/jdbc/CHANGELOG

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
Web Apr 12 22:14:00 BST 2000 peter@retep.org.uk
1+
Wed May 02 16:47:00 BST 2000 petermount@it.maidstone.gov.uk
2+
- Fixed the Makefile so that postgresql.jar is built everytime
3+
the jdbc1 or jdbc2 rules are called.
4+
- Fixed the threadsafe example. It had problems with autocommit
5+
6+
Wed May 02 14:32:00 BST 2000 petermount@it.maidstone.gov.uk
7+
- Rewrote the README file (the old one was 18 months old!)
8+
- Added @deprecated tags to org.postgresql.jdbc2.ResultSet
9+
to clear some warnings issued during compilation.
10+
11+
Wed Apr 12 22:14:00 BST 2000 peter@retep.org.uk
212
- Implemented the JDBC2 Blob interface, and ResultSet.getBlob().
313

414
Wed Apr 12 20:20:00 BST 2000 peter@retep.org.uk

src/interfaces/jdbc/Makefile

+13-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Makefile for Java JDBC interface
55
#
66
# IDENTIFICATION
7-
# $Id: Makefile,v 1.19 2000/04/26 14:19:29 momjian Exp $
7+
# $Id: Makefile,v 1.20 2000/05/03 15:58:08 peter Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -28,8 +28,8 @@ TOUCH = touch
2828
# postgresql to org/postgresql
2929
PGBASE = org/postgresql
3030

31-
# In 6.5, the all rule builds the makeVersion class which then calls make using
32-
# the jdbc1 or jdbc2 rules
31+
# For 6.5.3 and 7.0+, we need to select the correct JDBC API, so prompt
32+
# for the version.
3333
all:
3434
@echo ------------------------------------------------------------
3535
@echo Due to problems with some JVMs that dont return a meaningful
@@ -89,6 +89,7 @@ doc:
8989
# the jar file.
9090
OBJ_COMMON= $(PGBASE)/Connection.class \
9191
$(PGBASE)/Driver.class \
92+
$(PGBASE)/DriverClass.class \
9293
$(PGBASE)/Field.class \
9394
$(PGBASE)/PG_Stream.class \
9495
$(PGBASE)/ResultSet.class \
@@ -138,8 +139,12 @@ jdbc1:
138139
echo "public static String connectClass=\"org.postgresql.jdbc1.Connection\";" ;\
139140
echo "}" \
140141
) >$(PGBASE)/DriverClass.java
142+
-$(RM) postgresql.jar
141143
@$(MAKE) jdbc1real
142144

145+
# This rule does the real work for JDBC1.2, however do not call it directly.
146+
# This is because the JDBC driver relies on the org.postgresql.DriverClass
147+
# class to determine the driver version.
143148
jdbc1real: $(PGBASE)/DriverClass.class \
144149
$(OBJ_COMMON) $(OBJ_JDBC1) postgresql.jar msg
145150

@@ -150,17 +155,18 @@ jdbc2:
150155
echo "public static String connectClass=\"org.postgresql.jdbc2.Connection\";" ;\
151156
echo "}" \
152157
) >$(PGBASE)/DriverClass.java
158+
-$(RM) postgresql.jar
153159
@$(MAKE) jdbc2real
154160

161+
# This rule does the real work for JDBC2, however do not call it directly.
162+
# This is because the JDBC driver relies on the org.postgresql.DriverClass
163+
# class to determine the driver version.
155164
jdbc2real: $(PGBASE)/DriverClass.class \
156165
$(OBJ_COMMON) $(OBJ_JDBC2) postgresql.jar msg
157166

158167
# If you have problems with this rule, replace the $( ) with ` ` as some
159168
# shells (mainly sh under Solaris) doesn't recognise $( )
160169
#
161-
# Note: This works by storing all compiled classes under the $(PGBASE)
162-
# directory. We use this later for compiling the dual-mode driver.
163-
#
164170
postgresql.jar: $(OBJ) $(OBJ_COMMON)
165171
$(JAR) -c0f $@ `$(FIND) $(PGBASE) -name "*.class" -print` \
166172
$(wildcard $(PGBASE)/*.properties)
@@ -182,7 +188,7 @@ clean:
182188
#
183189
$(PGBASE)/Connection.class: $(PGBASE)/Connection.java
184190
$(PGBASE)/DatabaseMetaData.class: $(PGBASE)/DatabaseMetaData.java
185-
$(PGBASE)/Driver.class: $(PGBASE)/Driver.java
191+
$(PGBASE)/Driver.class: $(PGBASE)/Driver.java
186192
$(PGBASE)/Field.class: $(PGBASE)/Field.java
187193
$(PGBASE)/PG_Stream.class: $(PGBASE)/PG_Stream.java
188194
$(PGBASE)/PreparedStatement.class: $(PGBASE)/PreparedStatement.java

src/interfaces/jdbc/README

+97-54
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,37 @@
11
This is a simple readme describing how to compile and use the jdbc driver.
22

3-
This isn't a guide on how to use JDBC - for that refer to Javasoft's web site:
4-
5-
http://www.javasoft.com
3+
This file was amended on May 2 2000 to document the changes made in the 7.0
4+
release.
65

7-
or the JDBC mailing list:
6+
---------------------------------------------------------------------------
87

9-
jdbc@java.blackdown.org
8+
This isn't a guide on how to use JDBC - for that refer to Javasoft's web site:
109

11-
http://www.blackdown.org
10+
http://www.javasoft.com
1211

1312
For problems with this driver, then refer to the postgres-interfaces email
1413
list:
1514

1615
http://www.postgresql.org
1716

18-
When PostgreSQL V6.4 was released, full documentation for the driver was
19-
included in the main documentation tree (under the doc directory).
20-
21-
This file was finally amended on December 29 1998 to account for the major
22-
changes made to the driver since V6.4 was released.
23-
2417
---------------------------------------------------------------------------
2518

2619
COMPILING
2720

28-
To compile the driver, simply use make in the src/interfaces/jdbc directory.
29-
This will compile the driver, and build a .jar file (Java ARchive).
21+
There are actually two versions of the driver. One for the JDBC1.2 specification, and one for the JDBC2 specification. To compile the driver, you need to select the correct one.
3022

31-
REMEMBER: once you have compiled the driver, it will work on ALL platforms
32-
that support the JDK 1.1 api or later.
23+
If you have JDK1.1.x you need to type: make jdbc1
3324

34-
The V6.5 driver introduced support for the JDBC2 specification (which is used
35-
with JDK 1.2 api and later). This caused us some problems because classes
36-
written for JDBC1 and JDBC2 are not compatible, so a large chunk of the
37-
driver had to be re-written to accomodate this.
25+
If you have JDK1.2 or JDK1.3, you need to type: make jdbc2
3826

39-
Running make will build a .jar file (postgresql.jar) which contains the driver.
40-
That jar file will contain the driver for _your_ version of the JDK. That is,
41-
if you run make using JDK 1.1.7, then you will get the JDBC1 driver. If you
42-
run using 1.2 then you will get the JDBC2 driver.
27+
This will compile the driver, and build a .jar file (Java ARchive) called
28+
postgresql.jar
4329

44-
Tip: If you want the driver to run on both JDBC1 or JDBC2, first compile under
45-
JDK 1.1.x, then recompile under JDK 1.2.
30+
That jar file will contain the driver for _your_ version of the JDK.
4631

47-
In testing, I've done this using 1.1.6 (running under linux), and running make
48-
on my Win95 based Laptop (CygWin B20.1 was used to get a GNUMake - and a
49-
decent shell {bash}).
50-
51-
When the .jar file is built, it includes all the classes under postgresql, and
52-
the driver automatically selects the correct classes.
32+
REMEMBER: Once you have compiled the driver, it will work on ALL platforms
33+
that support that version of the API. You don't need to build it for each
34+
platform.
5335

5436
That means you don't have to compile it on every platform. Believe me, I
5537
still hear from people who ask me "I've compiled it ok under Solaris, but it
@@ -78,20 +60,12 @@ versions of the backend) on my web site http://www.retep.org.uk/postgres/
7860

7961
INSTALLING THE DRIVER
8062

81-
To install the driver, the .class files have to be in the classpath. This can be
82-
done in two ways:
83-
84-
1: create a directory "postgresql" (and it must be called this) in the current
85-
directory (or a directory in the class path), and copy all .class files
86-
into it.
63+
To install the driver, the .class files have to be in the classpath. To do
64+
this, copy the postgres.jar file into a directory, and add it to the classpath.
8765

88-
2: copy the postgres.jar file into a directory, and add it to the classpath.
66+
ie: under LINUX/SOLARIS (the example here is my linux box):
8967

90-
ie: under LINUX/SOLARIS (the example here is my linux box):
91-
92-
export CLASSPATH=.:/usr/local/lib/postgresql.jar:/usr/local/jdk1.1.1/lib/classes.zip
93-
94-
note: in java, .zip and .jar files hold collections of classes.
68+
export CLASSPATH=.:/usr/local/lib/postgresql.jar
9569

9670
---------------------------------------------------------------------------
9771

@@ -106,23 +80,24 @@ of doing this:
10680
introduce the driver using the following snippet of code:
10781

10882
try {
109-
Class.forName("postgresql.Driver");
83+
Class.forName("org.postgresql.Driver");
11084
} catch(Exception e) {
11185
// your error handling code goes here
11286
}
11387

11488
Remember, this method restricts your code to just the postgresql database.
89+
However, this is how most people load the driver.
11590

11691
2: Parameters
11792

11893
This method specifies the driver from the command line. When running the
11994
application, you specify the driver using the option:
12095

121-
-Djdbc.drivers=postgresql.Driver
96+
-Djdbc.drivers=org.postgresql.Driver
12297

12398
eg: This is an example of running one of my other projects with the driver:
12499

125-
java -Djdbc.drivers=postgresql.Driver finder.finder
100+
java -Djdbc.drivers=org.postgresql.Driver uk.org.retep.finder.Main
126101

127102
note: This method only works with Applications (not for Applets).
128103
However, the application is not tied to one driver, so if you needed
@@ -147,20 +122,88 @@ them to the URL. eg:
147122
jdbc:postgresql:database?user=me
148123
jdbc:postgresql:database?user=me&password=mypass
149124

150-
Previous versions you had to use an auth argument to tell the driver what
151-
authentication scheme to use when connecting to the database.
152-
153-
However, this is no longer supported because the database tells the driver
154-
what scheme it's expecting.
155-
156125
---------------------------------------------------------------------------
157126

158127
That's the basics related to this driver. You'll need to read the JDBC Docs
159-
on how to use it.
128+
on how to use it. However, there are some examples included in the example
129+
directory. To build, type: make examples
130+
131+
To run them, they follow the same syntax. For example, the basic example shows
132+
how to insert data, and perform queries:
133+
134+
java example.basic jdbc:postgresql:test user password
135+
136+
---------------------------------------------------------------------------
160137

161138
POSTGRESQL SPECIFICS
162139
--------------------
163140

141+
Large Objects:
142+
143+
A "feature" of PostgreSQL is that access to LargeObjects is only permitted
144+
within a Transaction. Because of this, any use of LargeObjects (also known
145+
as Blobs) requires that the Connection.setAutoCommit() method be called
146+
disabling the autocommit feature.
147+
148+
For example:
149+
150+
Connection db; // open the connection here
151+
db.setAutoCommit(false); // Turn off AutoCommit
152+
153+
------------------
154+
155+
Large Object API
156+
157+
Most of the time, you can use the getBytes()/setBytes() methods to read and
158+
write small Large Objects. However, PostgreSQL's own internal api's are
159+
available. These allow you to access the object as if it was a file.
160+
161+
The first thing you need to do is to open the LargeObjectManager. This class
162+
handles the opening of existing objects, and creating new ones. To do this,
163+
you use the following line of code:
164+
165+
LargeObjectManager lobj;
166+
lobj = ((org.postgresql.Connection)db).getLargeObjectAPI();
167+
168+
where db is a reference to an open Connection object.
169+
170+
Once that is done, you can use the API for the lifetime of that Connection.
171+
172+
To create an object, you call the create() method. This takes an argument
173+
with the file modes you intend to use. The following line is normally
174+
sufficient:
175+
176+
int oid = lobj.create(LargeObjectManager.READ|LargeObjectManager.WRITE);
177+
178+
Here, lobj is the LargeObjectManager we have opened earlier, and oid is the
179+
Large Object's oid in the database.
180+
181+
To open an existing object, you use the open() method. This takes an oid, and
182+
the file permissions. It then returns a LargeObject object.
183+
184+
LargeObject obj = lobj.open(oid,LargeObjectManager.WRITE);
185+
186+
Once the LargeObject is open, you can call methods to read, write, seek etc.
187+
Here's the supported methods:
188+
189+
int oid = obj.getOID(); Return the objects oid
190+
obj.close(); Close the object
191+
byte data[] = obj.read(int len); Read len bytes
192+
onj.read(byte data[],int off,int len); Read into data[off] len bytes
193+
obj.write(byte data[]); Write the array data
194+
obj.write(byte data[],int off,int len); Write len bytes from data[off]
195+
obj.seek(int pos,int ref); As fseek in C.
196+
obj.seek(int pos); Move to pos (from the begining)
197+
int pos = obj.tell(); Returns the current position
198+
int size = obj.size(); Returns the objects size
199+
200+
Caveat: If you commit(), rollback() a transaction, or turn on autocommit whilst
201+
an object is open PostgreSQL will close it. You will need to reopen the object
202+
before using it again. Using the existing LargeObject will cause an
203+
SQLException to be thrown.
204+
205+
------------------
206+
164207
Date datatype:
165208

166209
The driver now issues the "show datestyle;" query when it first connects, so

src/interfaces/jdbc/example/ImageViewer.java

+8
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,20 @@ public void actionPerformed(ActionEvent e) {
210210
public void init()
211211
{
212212
try {
213+
db.setAutoCommit(true);
213214
stat.executeUpdate("create table images (imgname name,imgoid oid)");
214215
label.setText("Initialised database");
215216
db.commit();
216217
} catch(SQLException ex) {
217218
label.setText(ex.toString());
218219
}
220+
221+
// This must run outside the previous try{} catch{} segment
222+
try {
223+
db.setAutoCommit(true);
224+
} catch(SQLException ex) {
225+
label.setText(ex.toString());
226+
}
219227
}
220228

221229
/**

0 commit comments

Comments
 (0)