Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Image store using Servlet

Thread view: 
Nike - 06 Nov 2006 13:34 GMT
How can i store image file (jpg , gif) in database MySQL via servlets ?
Simon Brooke - 06 Nov 2006 20:52 GMT
> How can i store image file (jpg , gif) in database MySQL via servlets ?

As an example:

/**
* Add or edit a picture in the database.
*
* @author Simon Brooke
* @version $Revision: 1.5.2.1 $ This revision: $Author: simon_brooke $
*/
public class Picture extends ArticleAuxForm
{
       //~ Static fields/initializers ------------------------------------

       /** fields in my table: the article field */
       public static final String ARTICLEFN = Article.KEYFN;

       /** fields in my table: the author field */
       public static final String AUTHORFN = "author";

       /** fields in my table: the key field field */
       public static final String KEYFN = "Picture";

       /** fields in my table: the caption field */
       public static final String CAPTIONFN = "caption";

       /** the names of fields in my table: the URL field */
       public static final String URLFN = "url";

       /** the name of my table */
       public static final String TABLENAME = "PICTURE";

       //~ Methods -------------------------------------------------------

       /**
        * set up widgets to edit each of my fields
        */
       public void init( Context config ) throws InitialisationException
       {
               table = TABLENAME; // my table
               keyField = KEYFN; // its primary key

               Widget w =
                       addWidget( new SimpleDataMenuWidget( ARTICLEFN, "Article",
                                       "The article this picture is assigned to", "ARTICLE",
                                       "Article", "Title", false ) );
               w.setMandatory( "You must supply an article for this picture." );

               ImageFileMaybeUploadWidget fw =
                       new ImageFileMaybeUploadWidget( URLFN, "Picture", "The picture." );
               fw.setMandatory( "You must supply a picture." );
               fw.setSize( 128 );
               fw.valueType = FileMaybeUploadWidget.VALUE_IS_URL;
               addWidget( fw );

               w = new Widget( CAPTIONFN, "Caption", "The caption for the picture" );
               w.setMandatory( "You must supply a caption for this picture." );
               w.setSize( 128 );
               addWidget( w );

               w = new SimpleDataMenuWidget( AUTHORFN, "Artist/Photographer",
                               "The person who created this picture", "ACTOR", "Actor",
                               "Name", false );
               w.setSize( 8 );
               addWidget( w );
               super.init( config ); // do my superclass configuration
       }
}

This is using the Jacquard toolkit, from here:
http://www.weft.co.uk/library/jacquard/

The class above is part of the PRES content management system, from here:
http://www.weft.co.uk/products/PRES/

Disclosure: I wrote both.

Signature

simon@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/
;; This email may contain confidential or otherwise privileged
;; information, though, quite frankly, if you're not the intended
;; recipient and you've got nothing better to do than read other
;; folks' emails then I'm glad to have brightened up your sad little
;; life a tiny bit.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.