File tree Expand file tree Collapse file tree 6 files changed +80
-6
lines changed Expand file tree Collapse file tree 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+
17Tue Jan 30 22:24:00 GMT 2001 peter@retep.org.uk
28 - Fixed bug where Statement.setMaxRows() was a global setting. Now
39 limited to just itself.
Original file line number Diff line number Diff line change 66
77/**
88 *
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 $
1010 *
1111 * This example tests the basic components of the JDBC driver, and shows
1212 * how even the simplest of queries can be implemented.
@@ -86,7 +86,7 @@ public void doexample() throws SQLException
8686 // This shows how to get the oid of a just inserted row
8787 // updated for 7.1
8888 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 ();
9090 System .out .println ("Inserted row with oid " +insertedOID );
9191
9292 // Now change the value of b from 1 to 8
Original file line number Diff line number Diff line change 99 <property category =" sys" name =" CheckStable" value =" 1" />
1010 <property category =" sys" name =" Company" value =" " />
1111 <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" />
1313 <property category =" sys" name =" Description" value =" " />
1414 <property category =" sys" name =" DocPath" value =" doc" />
1515 <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
9090 */
9191 public void close () throws SQLException
9292 {
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 ;
94100 }
95101
96102 /**
@@ -327,4 +333,18 @@ public String getResultStatusString()
327333 return null ;
328334 return ((org .postgresql .ResultSet )result ).getStatusString ();
329335 }
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+
330350}
Original file line number Diff line number Diff line change 2222 * @see java.sql.Statement
2323 * @see ResultSet
2424 */
25- public class Statement implements java .sql .Statement
25+ public class Statement extends org . postgresql . Statement implements java .sql .Statement
2626{
2727 Connection connection ; // The connection who created us
2828 java .sql .ResultSet result = null ; // The current results
@@ -95,7 +95,13 @@ public int executeUpdate(String sql) throws SQLException
9595 */
9696 public void close () throws SQLException
9797 {
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 ;
99105 }
100106
101107 /**
You can’t perform that action at this time.
0 commit comments