Another attempt
authorPeter Mount <peter@retep.org.uk>
Wed, 26 Apr 2000 05:32:01 +0000 (05:32 +0000)
committerPeter Mount <peter@retep.org.uk>
Wed, 26 Apr 2000 05:32:01 +0000 (05:32 +0000)
src/interfaces/jdbc/CHANGELOG
src/interfaces/jdbc/example/ImageViewer.java
src/interfaces/jdbc/example/basic.java
src/interfaces/jdbc/example/blobtest.java
src/interfaces/jdbc/example/corba/StockDB.java
src/interfaces/jdbc/example/datestyle.java
src/interfaces/jdbc/example/metadata.java
src/interfaces/jdbc/example/psql.java
src/interfaces/jdbc/example/threadsafe.java

index 33305008df54e081a342ed803aa381db46573dc3..910eab30d10572ec04b1a2cd26eefa641efaeca8 100644 (file)
@@ -1,3 +1,23 @@
+Web Apr 12 22:14:00 BST 2000 peter@retep.org.uk
+   - Implemented the JDBC2 Blob interface, and ResultSet.getBlob().
+   
+Wed Apr 12 20:20:00 BST 2000 peter@retep.org.uk
+   - Fixed bug in ResultSet.absolute(). Negative rows are now supported.
+   - Implemented ResultSet.relative(), afterLast().
+   
+Tue Feb  1 21:40:00 GMT 2000 peter@retep.org.uk
+   - Finally imported the contributed javax extensions by Assaf Arkin
+     arkin@exoffice.com
+
+Mon Jan 24 21:00:00 GMT 2000 peter@retep.org.uk
+   - Finally introduced the 7.0 additions to the core CVS repository.
+   - All source files are now under the org.postgresql package (previously
+     they were under postgresql). The package lines now changed
+     accordingly.
+   - The Makefile was rewritten so it should now work on machines that
+     can't handle the $( ) syntax.
+   - Dutch translation by Arnout Kuiper (ajkuiper@wxs.nl)
+
 Mon Sep 13 23:56:00 BST 1999 peter@retep.org.uk
    - PG_Stream.SendChar() optimised, increased default buffer size of
      output stream to 8k, and introduced an 8k buffer on the input stream
index 56166807d70515623aa189158dd61e400b23622d..a71f7b103c7c512e31e97c4b2576c7d3254ce78d 100644 (file)
@@ -4,7 +4,7 @@ import java.awt.*;
 import java.awt.event.*;
 import java.io.*;
 import java.sql.*;
-import postgresql.largeobject.*;
+import org.postgresql.largeobject.*;
 
 /**
  * This example is a small application that stores and displays images
@@ -14,11 +14,11 @@ import postgresql.largeobject.*;
  * on the first time you run it, select "Initialise" in the "PostgreSQL"
  * menu.
  *
- * Important note: You will notice we import the postgresql.largeobject
- * package, but don't import the postgresql package. The reason for this is
+ * Important note: You will notice we import the org.postgresql.largeobject
+ * package, but don't import the org.postgresql package. The reason for this is
  * that importing postgresql can confuse javac (we have conflicting class names
- * in postgresql.* and java.sql.*). This doesn't cause any problems, as long
- * as no code imports postgresql.
+ * in org.postgresql.* and java.sql.*). This doesn't cause any problems, as
+ * long as no code imports org.postgresql.
  *
  * Under normal circumstances, code using any jdbc driver only needs to import
  * java.sql, so this isn't a problem.
@@ -183,7 +183,7 @@ public class ImageViewer implements ItemListener
     f.add("Center",canvas = new imageCanvas());
     
     // Load the driver
-    Class.forName("postgresql.Driver");
+    Class.forName("org.postgresql.Driver");
     
     // Connect to database
     System.out.println("Connecting to Database URL = " + url);
@@ -196,7 +196,7 @@ public class ImageViewer implements ItemListener
     db.setAutoCommit(false);
     
     // Also, get the LargeObjectManager for this connection
-    lom = ((postgresql.Connection)db).getLargeObjectAPI();
+    lom = ((org.postgresql.Connection)db).getLargeObjectAPI();
     
     // Now refresh the image selection list
     refreshList();
@@ -273,7 +273,7 @@ public class ImageViewer implements ItemListener
    
    try {
      // fetch the large object manager
-     LargeObjectManager lom = ((postgresql.Connection)db).getLargeObjectAPI();
+     LargeObjectManager lom = ((org.postgresql.Connection)db).getLargeObjectAPI();
      
      System.out.println("Importing file");
      // A temporary buffer - this can be as large as you like
@@ -425,7 +425,7 @@ public class ImageViewer implements ItemListener
   {
     System.err.println("java example.ImageViewer jdbc-url user password");
     System.err.println("\nExamples:\n");
-    System.err.println("java -Djdbc.driver=postgresql.Driver example.ImageViewer jdbc:postgresql:test postgres password\n");
+    System.err.println("java -Djdbc.driver=org.postgresql.Driver example.ImageViewer jdbc:postgresql:test postgres password\n");
     
     System.err.println("This example tests the binary large object api of the driver.\nBasically, it will allow you to store and view images held in the database.");
     System.err.println("Note: If you are running this for the first time on a particular database,\nyou have to select \"Initialise\" in the \"PostgreSQL\" menu.\nThis will create a table used to store image names.");
@@ -442,7 +442,7 @@ public class ImageViewer implements ItemListener
     }
     
     try {
-      Frame frame = new Frame("PostgreSQL ImageViewer v6.4 rev 1");
+      Frame frame = new Frame("PostgreSQL ImageViewer v7.0 rev 1");
       frame.setLayout(new BorderLayout());
       ImageViewer viewer = new ImageViewer(frame,args[0],args[1],args[2]);
       frame.pack();
index dbd01d31bacacb3de61e0de0b0e4549e890d37a3..326c49c0f17e48665c7f89aba406f48418ec4fef 100644 (file)
@@ -5,12 +5,17 @@ import java.sql.*;
 import java.text.*;
 
 /**
+ *
+ * $Id: basic.java,v 1.4 2000/04/26 05:32:00 peter Exp $
+ *
  * This example tests the basic components of the JDBC driver, and shows
  * how even the simplest of queries can be implemented.
  *
  * To use this example, you need a database to be in existence. This example
  * will create a table called basic.
  *
+ * Note: This will only work with post 7.0 drivers.
+ *
  */
 
 public class basic
@@ -25,7 +30,7 @@ public class basic
     String pwd = args[2];
     
     // Load the driver
-    Class.forName("postgresql.Driver");
+    Class.forName("org.postgresql.Driver");
     
     // Connect to database
     System.out.println("Connecting to Database URL = " + url);
index 9ef64183ef7768450651e33a748ec5a52c4befbb..e08ff5b6fe13d67630ae22f2b6bcecb84501655f 100644 (file)
@@ -2,17 +2,17 @@ package example;
 
 import java.io.*;
 import java.sql.*;
-import postgresql.largeobject.*;
+import org.postgresql.largeobject.*;
 
 /**
  * This test attempts to create a blob in the database, then to read
  * it back.
  *
- * Important note: You will notice we import the postgresql.largeobject
- * package, but don't import the postgresql package. The reason for this is
+ * Important note: You will notice we import the org.postgresql.largeobject
+ * package, but don't import the org.postgresql package. The reason for this is
  * that importing postgresql can confuse javac (we have conflicting class names
- * in postgresql.* and java.sql.*). This doesn't cause any problems, as long
- * as no code imports postgresql.
+ * in org.postgresql.* and java.sql.*). This doesn't cause any problems, as
+ * long as no code imports org.postgresql.
  *
  * Under normal circumstances, code using any jdbc driver only needs to import
  * java.sql, so this isn't a problem.
@@ -35,12 +35,17 @@ public class blobtest
     String pwd = args[2];
     
     // Load the driver
-    Class.forName("postgresql.Driver");
+    Class.forName("org.postgresql.Driver");
     
     // Connect to database
     System.out.println("Connecting to Database URL = " + url);
     db = DriverManager.getConnection(url, usr, pwd);
-    System.out.println("Connected...Now creating a statement");
+    
+    // This is required for all LargeObject calls
+    System.out.println("Connected... First turn off autoCommit()");
+    db.setAutoCommit(false);
+    
+    System.out.println("Now creating a statement");
     s = db.createStatement();
     
     // Now run tests using postgresql's own Large object api
@@ -66,16 +71,22 @@ public class blobtest
    */
   public void ownapi() throws FileNotFoundException, IOException, SQLException
   {
-    System.out.println("\n----------------------------------------------------------------------\nTesting postgresql large object api\n");
+    System.out.println("\n----------------------------------------------------------------------\nTesting postgresql large object api\n----------------------------------------------------------------------\n");
     
     // Internally, the driver provides JDBC compliant methods to access large
-    // objects, however the unique methods available to postgresql makes things 
+    // objects, however the unique methods available to postgresql makes
+    // things a little easier.
     System.out.println("Gaining access to large object api");
-    lobj = ((postgresql.Connection)db).getLargeObjectAPI();
+    lobj = ((org.postgresql.Connection)db).getLargeObjectAPI();
     
     int oid = ownapi_test1();
     ownapi_test2(oid);
-    //ownapi_test3(oid);
+    
+    // Now call the jdbc2api test
+    jdbc2api(oid);
+    
+    // finally delete the large object
+    ownapi_test3(oid);
     System.out.println("\n\nOID="+oid);
   }
   
@@ -157,21 +168,63 @@ public class blobtest
     lobj.unlink(oid);
   }
   
-  //=========================================================================
+    //=======================================================================
+    // This tests the Blob interface of the JDBC 2.0 specification
+    public void jdbc2api(int oid) throws SQLException, IOException
+    {
+   System.out.println("Testing JDBC2 Blob interface:");
+   jdbc2api_cleanup();
+   
+   System.out.println("Creating Blob on large object "+oid);
+   s.executeUpdate("create table basic (a oid)");
+   
+   System.out.println("Inserting row");
+   s.executeUpdate("insert into basic values ("+oid+")");
+   
+   System.out.println("Selecting row");
+   ResultSet rs = s.executeQuery("select a from basic");
+   if(rs!=null) {
+       while(rs.next()) {
+       System.out.println("Fetching Blob");
+       Blob b = rs.getBlob("a");
+       System.out.println("Blob.length() = "+b.length());
+       System.out.println("Characters 400-500:");
+       System.out.write(b.getBytes(400l,100));
+       System.out.println();
+       }
+       rs.close();
+   }
+   
+   System.out.println("Cleaning up");
+   jdbc2api_cleanup();
+    }
+    
+    private void jdbc2api_cleanup() throws SQLException
+    {
+   db.setAutoCommit(true);
+   try {
+       s.executeUpdate("drop table basic");
+   } catch(Exception ex) {
+       // We ignore any errors here
+   }
+   db.setAutoCommit(false);
+    }
+    
+    //=======================================================================
   
   public static void instructions()
   {
     System.err.println("java example.blobtest jdbc-url user password [debug]");
     System.err.println("\nExamples:\n");
-    System.err.println("java -Djdbc.driver=postgresql.Driver example.blobtest jdbc:postgresql:test postgres password\nThis will run the tests on the database test on the local host.\n");
-    System.err.println("java -Djdbc.driver=postgresql.Driver example.blobtest jdbc:postgresql:test postgres password debug\nThis is the same as above, but will output debug information.\n");
+    System.err.println("java -Djdbc.driver=org.postgresql.Driver example.blobtest jdbc:postgresql:test postgres password\nThis will run the tests on the database test on the local host.\n");
+    System.err.println("java -Djdbc.driver=org.postgresql.Driver example.blobtest jdbc:postgresql:test postgres password debug\nThis is the same as above, but will output debug information.\n");
     
     System.err.println("This example tests the binary large object api of the driver.\nThis allows images or java objects to be stored in the database, and retrieved\nusing both postgresql's own api, and the standard JDBC api.");
   }
   
   public static void main(String args[])
   {
-    System.out.println("PostgreSQL blobtest v6.3 rev 1\n");
+    System.out.println("PostgreSQL blobtest v7.0 rev 1\n");
     
     if(args.length<3) {
       instructions();
index 49ceb1434c38888260b21c2f1511cc173db1a2d3..f2ef2463c82a0533d7b3a1a4a251888a0db0a80f 100644 (file)
@@ -13,7 +13,7 @@ import java.sql.*;
  * that an object could be changed by another client, and we need to ensure that
  * the returned data is live and accurate.
  *
- * $Id: StockDB.java,v 1.1 1999/01/25 21:22:03 scrappy Exp $
+ * $Id: StockDB.java,v 1.2 2000/04/26 05:32:01 peter Exp $
  */
 public class StockDB
 {
@@ -24,7 +24,7 @@ public class StockDB
     int id = -1;
     
     public void connect(String url,String usr,String pwd) throws Exception {
-   Class.forName("postgresql.Driver");
+   Class.forName("org.postgresql.Driver");
    System.out.println("Connecting to "+url);
    con = DriverManager.getConnection(url,usr,pwd);
    st = con.createStatement();
index eb412a7bd8916cc8275f076b277ccc17347dbc97..af8c87ae78eea2b571023334f8609eff7d97ab9e 100644 (file)
@@ -38,7 +38,7 @@ public class datestyle
     String pwd = args[2];
     
     // Load the driver
-    Class.forName("postgresql.Driver");
+    Class.forName("org.postgresql.Driver");
     
     // Connect to database
     System.out.println("Connecting to Database URL = " + url);
index a1c4e93293be836625037d62b9d6cd97f5ff8166..8d674122739ccae23146619405c0729526f48947 100644 (file)
@@ -113,7 +113,7 @@ public class metadata
     String pwd = args[2];
     
     // Load the driver
-    Class.forName("postgresql.Driver");
+    Class.forName("org.postgresql.Driver");
     
     // Connect to database
     System.out.println("Connecting to Database URL = " + url);
index 2ad18b198bf53a5ad765c760821c50d9e5c73221..1493a3b8220e944057e5de13f5d240732173893f 100644 (file)
@@ -23,7 +23,7 @@ public class psql
     String pwd = args[2];
     
     // Load the driver
-    Class.forName("postgresql.Driver");
+    Class.forName("org.postgresql.Driver");
     
     // Connect to database
     System.out.println("Connecting to Database URL = " + url);
index 48dff108f13a4fc0c0d879b1794ae672865b527c..5fbd1ce7307f0b9531dc4fe5d4258c9344de0587 100644 (file)
@@ -5,7 +5,7 @@ import java.sql.*;
 import java.text.*;
 
 // rare in user code, but we use the LargeObject API in this test
-import postgresql.largeobject.*;
+import org.postgresql.largeobject.*;
 
 /**
  * This example tests the thread safety of the driver.
@@ -28,7 +28,7 @@ public class threadsafe
     String pwd = args[2];
     
     // Load the driver
-    Class.forName("postgresql.Driver");
+    Class.forName("org.postgresql.Driver");
     
     // Connect to database
     System.out.println("Connecting to Database URL = " + url);
@@ -263,7 +263,7 @@ public class threadsafe
       //st = c.createStatement();
       
       // create a blob
-      lom = ((postgresql.Connection)c).getLargeObjectAPI();
+      lom = ((org.postgresql.Connection)c).getLargeObjectAPI();
       oid = lom.create();
       System.out.println("Thread 3 has created a blob of oid "+oid);
     }