Urgent : how to put an image into database and how to get it from it?

hi,
in the database i made a longblob type for image, and in my java code i have the path of the image (String): "C:\............." and i want to put this image in my data base.
also i want to know how to get the image after put it in the database.
please help me, it's so urgent.

This is a way of getting the image out of the database.
class yourClass{
private byte[] buff;
private ByteArrayOutputStream byteArrayOutputStream;
public yourClass()
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet result = statement.executeQuery("your query");
while ( result.next()){
try{
BufferedInputStream bin = new BufferedInputStream(rs.getBinaryStream("imagecolumn"));
byteArrayOutputStream = new ByteArrayOutputStream();
int length = bin.available();
buff = new byte[length];
while ( bin.read( buff, 0, length ) != -1 ) {
byteArrayOutputStream.write( buff, 0, length );
bin.close();
catch(Exception e){
The class about is used to take the image out of the database and store it in an object which is then streamed out through a servlet to display on the jsp page.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class ImageServlet extends HttpServlet {
public void init() throws ServletException {    }
public void destroy() {    }
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try
yourClass pro = (yourClass)request.getSession().getAttribute("object");
while ( iterator.hasNext() ) {
pro = ( Product ) iterator.next();
response.setContentType("image/jpg");
ByteArrayOutputStream byteArrayOutputStream = pro.getImage();
response.setContentLength( byteArrayOutputStream.size() );
response.getOutputStream().write( byteArrayOutputStream.toByteArray() );
response.getOutputStream().flush();
return;
catch (Exception e)
e.printStackTrace();
throw new ServletException(e);
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
This is a little messy but if you search the forums you will find out more on it. Search for Images and database.

Similar Messages

  • How to place an image in database and how to retrieve and display it in the front end

    how to place an image in database and how to retrieve and display it in the front end
    and to place an image in database and retrieve the image from database using xml
    please,help me out.

    Create a table with a Long RAW Datatype column for storing the Image Column Data.
    Create the form based on the table , which by defaults the column with LONG RAW atatype to a Image Item.
    You can use Forms Built in function READ_IMAGE_FILE to read a Image file stored on the file system in to the image item.
    A save on the form saves the image in the Image item in the long raw column.

  • How to store an image into database table

    Hi
    Can anyone tell me the way, how to store an image into database table.

    Hello,
    May be this thread will help you in your requirement.
    [FM for uploading Image to SAP;
    Thanks,
    Jayant

  • How to put the data into cache and distribute to nodeusing oracle coherence

    Hi Friends,
    i am having some random number data writing into file,from that file i am reading the data and i want to put into cache,how can i put the data into cache and partition this data into different nodes ( machines) to caluculate like S.D,variance..etc..like that.(or how can i implement montecarlo using oracle coherence) if any one know plz suggest me with flow.
    Thank you.
    regards
    chandra

    Hi robert,
    i have some bulk data in some arraylist or object format,i want to put into cache.
    i am not able to put into cache.i am using put method like cache.put(object key ,object value) ,but its not allowing to put into cache.
    can you please help me.i m sending my code.plz go thru and tel me whr i did mistake.
    package lab3;
    import com.tangosol.net.CacheFactory;
    import com.tangosol.net.NamedCache;
    import com.tangosol.net.cache.NearCache;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.PrintWriter;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
    import java.util.Scanner;
    import javax.naming.Name;
    public class BlockScoleData {
         * @param args
         * s=The spot market price
         * x=the exercise price of the option
         * v=instantaneous standard deviation of s
         * r=risk free instantaneous rate of interest
         * t= time to expiration of the option
         * n – Number of MC simulations.
         private static String outputFile = "D:/cache1/sampledata2.txt";
    private static String inputFile = "D:/cache1/sampledata2.txt";
    NearCache cache;
    List<Credit> creditList = new ArrayList<Credit>();
         public void writeToFile(int noofsamples) {
              Random rnd = new Random();
              PrintWriter writer = null;
              try {
                   writer = new PrintWriter(outputFile);
                   for (int i = 1; i <= noofsamples; i++) {
                        double s = rnd.nextInt(200) * rnd.nextDouble();
                        //double x = rnd.nextInt(250) * rnd.nextDouble();
                        int t = rnd.nextInt(5);
                        double v = rnd.nextDouble() ;
                        double r = rnd.nextDouble() / 10;
                        //int n = rnd.nextInt(90000);
                        writer.println(s + " " + t + " " + v + " "
                                  + r );
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
              } finally {
                   writer.close();
                   writer = null;
    public List<Credit> readFromFile() {
    Scanner scanner = null;
    Credit credit = null;
    // List<Credit> creditList = new ArrayList<Credit>();
    try {
    scanner = new Scanner(new File(inputFile));
    while (scanner.hasNext()) {
    credit = new Credit(scanner.nextDouble(), scanner.nextInt(),
    scanner.nextDouble(), scanner.nextDouble());
    creditList.add(credit);
    System.out.println("read the list from file:"+creditList);
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } finally {
    scanner.close();
    credit = null;
    scanner = null;
    return creditList;
    // public void putCache(String cachename,List<Credit> list){
    // cache = CacheFactory.getCache ( "VirtualCache");
    // List<Credit> rand = new ArrayList<Credit>();
    public Object put(Object key, Object value){
    cache = (NearCache)CacheFactory.getCache("mycache");
    String cachename = cache.getCacheName();
    List<Credit> cachelist=new ArrayList<Credit>();
    // Object key;
    //cachelist = (List<Credit>)cache.put(creditList,creditList);
    cache.put(creditList,creditList);
    System.out.println("read to the cache list from file:"+cache.get(creditList));
    return cachelist;
         public static void main(String[] args) throws Exception {
         NearCache cache = (NearCache)CacheFactory.getCache("mycache");
              new BlockScoleData().writeToFile(20);
         //new BlockScoleData().putCache("Name",);
              System.out
                        .println("New file \"myfile.csv\" has been created to the current directory");
         CacheFactory.ensureCluster();
         new BlockScoleData().readFromFile();
    System.out.println("data read from file successfully");
         List<Credit> creditList = new ArrayList<Credit>();
    new BlockScoleData().put(creditList,creditList);
         System.out.println("read to the cache list from file:"+cache.get(creditList));
    //cache=CacheFactory.getCache("mycache");
    //mycacheput("Name",new BlockScoleData());
    //     System.out.println("name of cache is :" +mycache.getCacheName());
    //     System.out.println("value in cache is :" +mycache.get("Name"));
    //     System.out.println("cache services are :" +mycache.getCacheService());
    regards
    chandra

  • How to save an image to database and retreive from it.

    how to save an image retreived from an bytearray to database and retreive back the image from database....pls specify the steps and the query.

    You can use the JDBC API for database connectivity and you can use SQL to query the database.
    JDBC tutorial: http://www.google.com/search?q=jdbc+tutorial+site:sun.com
    SQL tutorial: http://www.google.com/search?q=sql+tutorial+site:w3schools.com

  • How do import an image into CS3 and resize it?

    Hi, let me say first I know very little of Illustrator C3.  I have a poster that was created by someone else.  I'm supposed to take that image and resize to fit on a pop up banner.  I created a new doc in Ill. with the correct dimensions and copied and pasted the image.  Now how to I get the original image with layers to conform to the new doc. sizing?  I need to take the image and enlarge it and make it fit within the confines of my new doc.  How do I do that without distorting the image.

    Shift, Ctrl and Alt modifier keys offer constraining options in all Adobe programs. Shift will retain proportions, Alt scale from the center etc. and when combined you can scale constrained from the center. anyway, the question is, what you are referring to by "image". Bitmaps as in photographs or other pixel images? Then AI is the wrong choice. You need to do such things in Photoshop. If its a PDF or another AI file, scaling should be no problem. you may just wish to group items before doing so to retain their relative placement within teh group and avoid unpleasant surprises when you only mass-select them.
    Mylenium

  • How to change the image into byte and byte array into image

    now i am developing one project. i want change the image into byte array and then byte array into image.

    FileInputStream is = new FileInputStream(file);
    byte[] result = IOUtils.toByteArray(is);
    with apache common IO lib

  • How finder shares multiple images at once and how can I use this in my app?

    You can share multiple images (or other documents) at once in finder. It's probably possible to make an app in Xcode that does exactly the same thing as well, but I don't know how. I really want to because I'm a bit curios. I would love if there are some code examples on the web so I can check it out. Can you help me?

    Matic Conradi wrote:
    .... I would love if there are some code examples on the web so I can check it out. Can you help me?
    Is your Google broken?

  • How to export dynamic images into pdf

    Hi,
    I need to export a image into PDF which we are getting it from DBase. This returns me the image as BLOB and this we are putting it in between the xml tags. I am passing the xml to xsl-fo. While i tried to export the xml data into pdf using xsl-fo, the content is getting exported into pdf but not the image. I am using FOP, and i have added fop.jar, batik.jar, avalon-xx.jar, jai_codec.jar and jai_core.jar to my class path. I am putting my sample xsl and xml here.
    xml:
    <RTFDrugReport>
    <ImagePath>http://www.thomson-pharma.com/tp/images</ImagePath>
    <NewsEdge>
    <NewsItem>
    <StoryId><![CDATA[200705223600.15_2774000daba43be0]]></StoryId>
    <HeadlineText><![CDATA[NeuroLogica's CereTom Supplies On Site Post-Fight Brain CT During De  La Hoya-Mayweather Weekend]]></HeadlineText>
    <ItemTime><![CDATA[05/23/2007 03:22:24 AM EDT]]></ItemTime>
    </NewsItem>
    </NewsEdge>
    </RTFDrugReport>
    xsl:
    <fo:static-content flow-name="xsl-region-before">
    <fo:block font-family="Helvetica" font-size="14pt" text-align="left" white-space-collapse="false">
    <xsl:variable name="imageName" select="concat(//ImagePath,'/logo_thomson_pharma.png')"/>
    <fo:external-graphic src="'{$imageName}'"/>first
    <fo:external-graphic src="url('{$imageName}')"/>second
    <xsl:value-of select="'{$imageName}'"/>thrid
    <fo:external-graphic src="'{$imageName}'" content-width="100mm" content-height="100mm"/>fourth
    <fo:external-graphic src="'{$imageName}'" content-width="100mm" content-height="100mm"/>fifth
    <fo:instream-foreign-object src='url("///file:/D:/Customization/collage.jpg")' height="3cm" width="3cm"/>
    </fo:block>
    </fo:static-content>
    Any help would be appreciated.

    hi,
    all the UI elements in the adobe form are generally connected to your web-dynpro Context.
    whatever you type in the online adobe form is reflected in the respective context attributes of the dynpro Context of the view where "ur Interactive form UI element is".
    that means you can yourself fill the contents of ur interactive form by working on the get/set methods of the context attributes.
    Likewise you can clear the form by setting all context attributes to blank eg ""
    <b>interactive form has two imp properties:-</b>
    <b>*dataSource</b>
    data source points to the node all whose context attributes will be made available in the interactive form
    <b>*pdfsource</b>
    points to the context attribute which will hold the pdf.
    note that the type of this pdfSorce attribute will be binary.
    if you still have doubts.
    give me your gmail mail id. i 'll send a tutorial.
    with regards,
    -ag.

  • I have taken pictures of items that are linked to a database that I am building.  How can I bypass importing into iPhoto and simply downloading the images as "files" not "photos" so I can access them with my database?  thanx.

    I have taken pictures with both my Sony camera and my iPhone of items that are linked to a database that I am building, as well as my website.  How can I bypass importing the images into iPhoto and simply downloading the images as "files" not "photos" so I can access them with my database?  thanx.

    If your Sony has a removable memory card you can use a card reader to copy the image files from to a folder on your Desktop and then move them anywhere you'd like.
    Since the iPhone doesn't have a removable memory card you can try using Image Capture to see if you can manually upload the files to a folder on the Desktop. 
    If you have to import the photos, which are image files, into iPhoto you can then export them out of iPhoto to the Desktop and go from there to your database.  Just because they are in iPhoto doesn't prevent you from using them elsewhere.
    OT

  • How to insert an image into mysql

    welcome to all,
    can any one tell how to insert an image into mysql database(BLOB). it is urgent.
    regards

    welcome to all,
    can any one tell how to insert an image into mysql database(BLOB). it is urgent.
    regards

  • Save images into database

    hello, i have been fighting with this for some days, i have a picture that i load with de filerence.load method. and then,
    i use the filereference.data to show the picture into the image control.
    i need to save the image into database, but i can't. i don't know how i can convert the bytearray into hexa string or binary!!!

    Hi Sai,
           I am getting the error ArgumentError: Error #2015: Invalid
    BitmapData. When I am trying to change the image into byteArray using
    BitMapData.
          Below is the code i am using for this scenario. I am trying to get
    byteArray of the image after the image is completely loaded in the
    onComplete().
    private function initFunction(event:Event):void{
    uploadFile =new FileReference();
    imgTypes=new FileFilter("images(.JPG,.JPEG,.PNG,.GIF)",*
    ".JPG;.JPEG,.PNG;.GIF;"*);
    private function browseFile():*void
    uploadFile.addEventListener(Event.SELECT, onFileSelected);
    *try
    uploadFile.browse();
    catch(err:Error)
    logData(err.message);
    private function onFileSelected(event:Event):*void
    uploadFile.addEventListener(ProgressEvent.PROGRESS, onProgress);
    uploadFile.addEventListener(Event.COMPLETE, onComplete);
    uploadFile.load();
    private function onProgress(event:ProgressEvent):*void
    logData("Loaded " + event.bytesLoaded + " of " + event.bytesTotal + *"
    bytes."*);
    private function onComplete(evt:Event):*void
    logData("File was successfully loaded.");
    *//image.source = uploadFile.data;
    image.source=uploadFile.name;
    Alert.show("image source:"+image.source);
    var bitmapData:BitmapData = new BitmapData(image.width,image.height);
    var ba:ByteArray = png.encode(bitmapData);
    Alert.show("bytes loaded"+ba);
    Thanks,
    Ravi.
    On Sat, Nov 20, 2010 at 9:19 PM, ravindharreddy Baddam <

  • How to load an image into blob in a custom form

    Hi all!
    is there some docs or how to, load am image into a database blob in a custom apps form.
    The general idea is that the user has to browse the local machine find the image, and load the image in a database blob and also in the custom form and then finally saving the image as blob.
    Thanks in advance
    Soni

    If this helps:
    Re: Custom form: Take a file name input from user.
    Thanks
    Nagamohan

  • Putting an image into a JFrame or a JPanel

    Hello everybody,
    I'd like to know how to put an image (a real one, not a small icon we can't see it!) into a JFrame, or a JPanel, or included into a miscellanea element (label, textfield or somethiong else).
    Thanks,
    Regards
    Cedric

    Hi Cedric,
    If the image format is Jpg or gif, then the best way to insert the image
    into the Frame or panel is to use JLabel. You can pass the argument to the file as parameter to JLabel construction.
    For other formats, you have the option of using drawimage in paint function of applets.
    Hope this helps.
    Best Regards,
    Chandru

  • How to put html file into a canevas?

    How to put html file into a canevas?

    Hi,
    would require you to write a JavaBean that interprets the HTML (there are commercial versions of this available)
    Frank

Maybe you are looking for