File tree 6 files changed +80
-6
lines changed
6 files changed +80
-6
lines changed Original file line number Diff line number Diff line change
1
+ Wed Jan 31 08:46:00 GMT 2001 peter@retep.org.uk
2
+ - Some minor additions to Statement to make our own extensions more
3
+ portable.
4
+ - Statement.close() will now call ResultSet.close() rather than just
5
+ dissasociating with it.
6
+
1
7
Tue Jan 30 22:24:00 GMT 2001 peter@retep.org.uk
2
8
- Fixed bug where Statement.setMaxRows() was a global setting. Now
3
9
limited to just itself.
Original file line number Diff line number Diff line change 6
6
7
7
/**
8
8
*
9
- * $Id: basic.java,v 1.6 2001/01/31 08:26:01 peter Exp $
9
+ * $Id: basic.java,v 1.7 2001/01/31 09:23:45 peter Exp $
10
10
*
11
11
* This example tests the basic components of the JDBC driver, and shows
12
12
* how even the simplest of queries can be implemented.
@@ -86,7 +86,7 @@ public void doexample() throws SQLException
86
86
// This shows how to get the oid of a just inserted row
87
87
// updated for 7.1
88
88
st .executeUpdate ("insert into basic values (4,1)" );
89
- int insertedOID = ((org .postgresql .jdbc2 . Statement )st ).getInsertedOID ();
89
+ int insertedOID = ((org .postgresql .Statement )st ).getInsertedOID ();
90
90
System .out .println ("Inserted row with oid " +insertedOID );
91
91
92
92
// Now change the value of b from 1 to 8
Original file line number Diff line number Diff line change 9
9
<property category =" sys" name =" CheckStable" value =" 1" />
10
10
<property category =" sys" name =" Company" value =" " />
11
11
<property category =" sys" name =" Copyright" value =" Copyright (c) 2001" />
12
- <property category =" sys" name =" DefaultPackage" value =" org.postgresql.largeobject " />
12
+ <property category =" sys" name =" DefaultPackage" value =" org.postgresql" />
13
13
<property category =" sys" name =" Description" value =" " />
14
14
<property category =" sys" name =" DocPath" value =" doc" />
15
15
<property category =" sys" name =" ExcludeClassEnabled" value =" 0" />
Original file line number Diff line number Diff line change
1
+ package org .postgresql ;
2
+
3
+ import java .sql .SQLException ;
4
+
5
+ /**
6
+ * This class defines methods implemented by the two subclasses
7
+ * org.postgresql.jdbc1.Statement and org.postgresql.jdbc2.Statement that are
8
+ * unique to PostgreSQL's JDBC driver.
9
+ *
10
+ * <p>They are defined so that client code can cast to org.postgresql.Statement
11
+ * without having to predetermine the jdbc driver type.
12
+ *
13
+ * <p>ie: Before this class existed, you had to use:
14
+ *
15
+ * <p>((org.postgresql.jdbc2.Statement)stat).getInsertedOID();
16
+ *
17
+ * <p>now you use:
18
+ *
19
+ * <p>((org.postgresql.Statement)stat).getInsertedOID();
20
+ *
21
+ * <p>As you can see, this is independent of JDBC1.2, JDBC2.0 or the upcoming
22
+ * JDBC3.
23
+ */
24
+
25
+ public abstract class Statement {
26
+
27
+ public Statement () {
28
+ }
29
+
30
+ /**
31
+ * Returns the status message from the current Result.<p>
32
+ * This is used internally by the driver.
33
+ *
34
+ * @return status message from backend
35
+ */
36
+ public abstract String getResultStatusString ();
37
+
38
+ /**
39
+ * @return the OID of the last row inserted
40
+ */
41
+ public abstract int getInsertedOID () throws SQLException ;
42
+ }
Original file line number Diff line number Diff line change @@ -90,7 +90,13 @@ public int executeUpdate(String sql) throws SQLException
90
90
*/
91
91
public void close () throws SQLException
92
92
{
93
- result = null ;
93
+ // Force the ResultSet to close
94
+ java .sql .ResultSet rs = getResultSet ();
95
+ if (rs !=null )
96
+ rs .close ();
97
+
98
+ // Disasociate it from us (For Garbage Collection)
99
+ result = null ;
94
100
}
95
101
96
102
/**
@@ -327,4 +333,18 @@ public String getResultStatusString()
327
333
return null ;
328
334
return ((org .postgresql .ResultSet )result ).getStatusString ();
329
335
}
336
+
337
+ /**
338
+ * New in 7.1: Returns the Last inserted oid. This should be used, rather
339
+ * than the old method using getResultSet, which for executeUpdate returns
340
+ * null.
341
+ * @return OID of last insert
342
+ */
343
+ public int getInsertedOID () throws SQLException
344
+ {
345
+ if (result !=null )
346
+ return ((org .postgresql .ResultSet )result ).getInsertedOID ();
347
+ return 0 ;
348
+ }
349
+
330
350
}
Original file line number Diff line number Diff line change 22
22
* @see java.sql.Statement
23
23
* @see ResultSet
24
24
*/
25
- public class Statement implements java .sql .Statement
25
+ public class Statement extends org . postgresql . Statement implements java .sql .Statement
26
26
{
27
27
Connection connection ; // The connection who created us
28
28
java .sql .ResultSet result = null ; // The current results
@@ -95,7 +95,13 @@ public int executeUpdate(String sql) throws SQLException
95
95
*/
96
96
public void close () throws SQLException
97
97
{
98
- result = null ;
98
+ // Force the ResultSet to close
99
+ java .sql .ResultSet rs = getResultSet ();
100
+ if (rs !=null )
101
+ rs .close ();
102
+
103
+ // Disasociate it from us (For Garbage Collection)
104
+ result = null ;
99
105
}
100
106
101
107
/**
You can’t perform that action at this time.
0 commit comments