From 39116bfbfcf5d17956dca2a1a424e52488aa3f56 Mon Sep 17 00:00:00 2001 From: Peter Mount Date: Wed, 26 Apr 2000 05:32:01 +0000 Subject: [PATCH] Another attempt --- src/interfaces/jdbc/CHANGELOG | 20 +++++ src/interfaces/jdbc/example/ImageViewer.java | 20 ++--- src/interfaces/jdbc/example/basic.java | 7 +- src/interfaces/jdbc/example/blobtest.java | 83 +++++++++++++++---- .../jdbc/example/corba/StockDB.java | 4 +- src/interfaces/jdbc/example/datestyle.java | 2 +- src/interfaces/jdbc/example/metadata.java | 2 +- src/interfaces/jdbc/example/psql.java | 2 +- src/interfaces/jdbc/example/threadsafe.java | 6 +- 9 files changed, 112 insertions(+), 34 deletions(-) diff --git a/src/interfaces/jdbc/CHANGELOG b/src/interfaces/jdbc/CHANGELOG index 33305008df..910eab30d1 100644 --- a/src/interfaces/jdbc/CHANGELOG +++ b/src/interfaces/jdbc/CHANGELOG @@ -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 diff --git a/src/interfaces/jdbc/example/ImageViewer.java b/src/interfaces/jdbc/example/ImageViewer.java index 56166807d7..a71f7b103c 100644 --- a/src/interfaces/jdbc/example/ImageViewer.java +++ b/src/interfaces/jdbc/example/ImageViewer.java @@ -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(); diff --git a/src/interfaces/jdbc/example/basic.java b/src/interfaces/jdbc/example/basic.java index dbd01d31ba..326c49c0f1 100644 --- a/src/interfaces/jdbc/example/basic.java +++ b/src/interfaces/jdbc/example/basic.java @@ -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); diff --git a/src/interfaces/jdbc/example/blobtest.java b/src/interfaces/jdbc/example/blobtest.java index 9ef64183ef..e08ff5b6fe 100644 --- a/src/interfaces/jdbc/example/blobtest.java +++ b/src/interfaces/jdbc/example/blobtest.java @@ -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(); diff --git a/src/interfaces/jdbc/example/corba/StockDB.java b/src/interfaces/jdbc/example/corba/StockDB.java index 49ceb1434c..f2ef2463c8 100644 --- a/src/interfaces/jdbc/example/corba/StockDB.java +++ b/src/interfaces/jdbc/example/corba/StockDB.java @@ -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(); diff --git a/src/interfaces/jdbc/example/datestyle.java b/src/interfaces/jdbc/example/datestyle.java index eb412a7bd8..af8c87ae78 100644 --- a/src/interfaces/jdbc/example/datestyle.java +++ b/src/interfaces/jdbc/example/datestyle.java @@ -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); diff --git a/src/interfaces/jdbc/example/metadata.java b/src/interfaces/jdbc/example/metadata.java index a1c4e93293..8d67412273 100644 --- a/src/interfaces/jdbc/example/metadata.java +++ b/src/interfaces/jdbc/example/metadata.java @@ -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); diff --git a/src/interfaces/jdbc/example/psql.java b/src/interfaces/jdbc/example/psql.java index 2ad18b198b..1493a3b822 100644 --- a/src/interfaces/jdbc/example/psql.java +++ b/src/interfaces/jdbc/example/psql.java @@ -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); diff --git a/src/interfaces/jdbc/example/threadsafe.java b/src/interfaces/jdbc/example/threadsafe.java index 48dff108f1..5fbd1ce730 100644 --- a/src/interfaces/jdbc/example/threadsafe.java +++ b/src/interfaces/jdbc/example/threadsafe.java @@ -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); } -- 2.40.0