Save This Page
Home » struts-2.0.11.2-src » example » [javadoc | source]
example
public class: ImageViewer [javadoc | source]
java.lang.Object
   example.ImageViewer

All Implemented Interfaces:
    ItemListener

This example is a small application that stores and displays images held on a postgresql database. Before running this application, you need to create a database, and on the first time you run it, select "Initialise" in the "PostgreSQL" menu. 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 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. It's only if you use the non jdbc facilities, do you have to take this into account. Note: For PostgreSQL 6.4, the driver is now Thread safe, so this example application has been updated to use multiple threads, especially in the image storing and retrieving methods.
Nested Class Summary:
public class  ImageViewer.imageCanvas   
class  ImageViewer.importer  This is an example of using a thread to import a file into a Large Object. It uses the Large Object extension, to write blocks of the file to the database. 
Field Summary
 Connection db     
 Statement stat     
 LargeObjectManager lom     
 Frame frame     
 Label label     
 List list     
 ImageViewer.imageCanvas canvas     
 String currentImage     
Constructor:
 public ImageViewer(Frame f,
    String url,
    String user,
    String password) throws IOException, ClassNotFoundException, SQLException, FileNotFoundException 
Method from example.ImageViewer Summary:
close,   displayImage,   importImage,   init,   instructions,   itemStateChanged,   main,   refreshList,   removeImage
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from example.ImageViewer Detail:
 public  void close() 
    This closes the connection, and ends the application
 public  void displayImage(String name) 
    This displays an image from the database. For images, this is the easiest method.
 public  void importImage() 
    This imports an image into the database, using a Thread to do this in the background.
 public  void init() 
    This method initialises the database by creating a table that contains the image names, and Large Object OID's
 public static  void instructions() 
    This is the command line instructions
 public  void itemStateChanged(ItemEvent e) 
 public static  void main(String[] args) 
    This is the application entry point
 public  void refreshList() 
    This refreshes the list of available images
 public  void removeImage() 
    This removes an image from the database Note: With postgresql, this is the only way of deleting a large object using Java.