Inserting Images in Database

Hi,
I am using forms6 and database is 8.0.5. I have images stored in a folder say c:\images\. I have a table for item master and the item code is same as the image name in the image folder. Eg : Item code -ABC123 so there is a image jpeg format by the name ABC123. All the records are created in item master.
Now if the user puts 10 images in this folder i want to read all this images and insert it in item master against this item code. Now i want to know the sql for this
1>Reading sequentially all the images from this folder
2>By the image file name read the itemcode from the item master and insert image in that record. I am using Long raw for storing the images.
Thanks in advance.

Hi,
I managed reading the images from the folder and but just stuck up with the problem.
Test -1
I declared a variable var_abc long raw.
read_image_file(v_filename,'ANY',var_abc);
update item_master set item_pict = var_abc where item_code = var_item;
Here it gives error at runtime on read_image_file for var_abc
Test-2
I created a nondatabase block and create a column txt_image with type as image.
read_image_file(v_filename,'ANY',:txt_image);
update item_master set item_pict = :txt_image where item_code = var_item;
Here it gives error at compilation on item_pict =:txt_image
Anyone can help me out where i am making mistake ?.

Similar Messages

  • Inserting image in database

    i want to insert a image in database(mysql) using servlet/jsp.
    please help me out

    try it using file IO. when the file is read and store that in object and then try to insert

  • INSERTING IMAGE TO DATABASE TABLE

    please suggest me the simplest code of image insertion in the database table.

    this is an example:>
    public static void AddEmployee(
    string lastName,
    string firstName,
    string title,
    DateTime hireDate,
    int reportsTo,
    string photoFilePath,
    string connectionString)
    byte[] photo = GetPhoto(photoFilePath);
    using (SqlConnection connection = new SqlConnection(
    connectionString))
    SqlCommand command = new SqlCommand(
    "INSERT INTO Employees (LastName, FirstName, " +
    "Title, HireDate, ReportsTo, Photo) " +
    "Values(@LastName, @FirstName, @Title, " +
    "@HireDate, @ReportsTo, @Photo)", connection);
    command.Parameters.Add("@LastName",
    SqlDbType.NVarChar, 20).Value = lastName;
    command.Parameters.Add("@FirstName",
    SqlDbType.NVarChar, 10).Value = firstName;
    command.Parameters.Add("@Title",
    SqlDbType.NVarChar, 30).Value = title;
    command.Parameters.Add("@HireDate",
    SqlDbType.DateTime).Value = hireDate;
    command.Parameters.Add("@ReportsTo",
    SqlDbType.Int).Value = reportsTo;
    command.Parameters.Add("@Photo",
    SqlDbType.Image, photo.Length).Value = photo;
    connection.Open();
    command.ExecuteNonQuery();
    public static byte[] GetPhoto(string filePath)
    FileStream stream = new FileStream(
    filePath, FileMode.Open, FileAccess.Read);
    BinaryReader reader = new BinaryReader(stream);
    byte[] photo = reader.ReadBytes((int)stream.Length);
    reader.Close();
    stream.Close();
    return photo;
    Mark as answer or vote as helpful if you find it useful | Ammar Zaied [MCP]

  • Insert Image in database from Java Prog, but some excp. occured

    I want to insert the content of an Image file into my database, but I am getting the below exception.
    I am reading the file and taking the content into a string. The string displays perfectly (if I print the string using system.out.println statement) but while inserting into database it gives problem.
    Following is my code::
    import java.io.*;
    import java.sql.*;
    public class ImageInsert
    public static void main(String args[])
    try
    DataInputStream dis = new DataInputStream(new FileInputStream("reshmi.gif"));
    String str="" , ImageContent="";
    while((str = dis.readLine()) != null )
    ImageContent = ImageContent + str;
         //System.out.println("Content :"+ str);
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:somedata" , "sa" , "");
    Statement st = con.createStatement();
    String as = "INSERT INTO TESTIMAGE (ImageFile) VALUES(\"" + ImageContent + "\")" ;
    int q = st.executeUpdate(as);
    System.out.println("The data Inserted:"+q);
         }catch(Exception er) {er.printStackTrace();}
    // end of code
    Where as if I insert it manually in my SQL Server executing the insert statement it inserts the image perfectly:
    Following Exceptions I am receivng :
    *********** BELOW IS THE EXCEPTION********
    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Unclosed quotation m
    ark before the character string 'GIF89a��'.
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(Compiled Code)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:4246)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:1172)
    at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:206)
    at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:163)

    It looks like imageContent contains a quote character, making your statement invalid. Something like
    Insert into .... value("<some chars>..."...<some chars>")
    Using single quotes will not resolve this problem since imageContent could also contains single quote chars.
    Try using BLOBs instead strings. I don't know if SQLServer supports BLOBs but Oracle does.
    JCG

  • Jsp mysql insert image to database

    hi all
    my qry is this
    i have a register page and wish to give the user the option to upload there picture but i dont know quite how this is done
    i can insert all the rest of the data to my database am just unsure on the inserting of the image file
    can anybody help me out?
    thanks

    hi annie
    could you explain more.. i dont know what or how a
    blob field is
    thanksBLOB is Binary Large OBject field. You can store an image as binary data in such a field. Check this link for some code help:
    http://www.theserverside.com/discussions/thread.tss?thread_id=7401
    Annie.

  • Image in database

    Insert into table
    values(?,?)
    In one of the code for inserting image into database ,for values " ? " has been put.What am I suppose to put therre .while storing an image into oracle 9i database it gives me error as Invalid hex number.
    I am using JSP as my front end

    catch(Exception e)
    System.out.println(e);
    }Exceptions have the wonderful printStackTrace() method which show you which line and which sourcefile actually caused the exception.
    byte b[]=new byte[is.available()];
    is.read(b);This looks dangerous. available() is not guaranteed to return the total size of the image.

  • Inserting images is taking too much time(PT)

    Hi,
    when i'm inserting images into database 10g it is taking much time than usual ..and other dml operations are normal..how can i make it fast .thanks in advance
    Edited by: startup on Oct 10, 2011 4:53 PM
    Edited by: startup on Oct 10, 2011 5:18 PM

    startup wrote:
    Hi,
    when i'm inserting images into database it is taking much time than usual ..and other dml operations are normal..how can i make it fast .Maybe using "parallel" hints, Please provide your DB version and OS Name

  • How to Insert Hastables Into Database Through JDBC

    hi all,
    I have place the Data from the Hashtables Into the Database.I can place it by Iterating through the Hastables.I would Like to Place the Entire Hashtable Itself Into the Database.
    Can Any one tell me how?
    bye.

    Hi,
    Can anyone help me out how to insert image into
    database using struts...with dao n dto classes?If it matters whether or not you are using struts then you might have something wrong.
    Make sure you separate the database logic out.
    I know these types of questions are asked frequently, you might want to search the forum for additional examples.
    Here is a good one:
    http://forum.java.sun.com/thread.jspa?threadID=620455&messageID=3495899

  • Inserting image in to database !!

    Hi All,
    I have to insert image in to the database. My image is there in swing object Image. Is there any way to insert that image in to the database.
    Any body having knowledge on this, Please help.
    Thanks in advance.
    Regards,
    Roja.

    Hi
    Take a look to this code I found surfing, it creates an image from url then resize it and return it as byte array that you can use to set a blob in the database:
    public static byte [] resizeImage(URL url,int widthConstraint,int heightConstraint) throws ImageFormatException, IOException
         ImageIcon imageIcon = new ImageIcon(url);
         Image img = imageIcon.getImage();
         int imgWidth = imageIcon.getIconWidth();
         int imgHeight = imageIcon.getIconHeight();
         ImageIcon adjustedImg=null;
         if ( imgWidth>0 && imgHeight>0)//imgWidth > widthConstraint | imgHeight >  heightConstraint )
         if ( imgWidth > imgHeight )
           // Create a resizing ratio.
           double ratio = (double) imgWidth / (double)
            widthConstraint;
           int newHeight = (int) ( (double) imgHeight / ratio );
           // use Image.getScaledInstance( w, h,
           // constant), where constant is a constant
           // pulled from the Image class indicating how
           // process the image; smooth image, fast
           // processing, etc.
           adjustedImg = new ImageIcon(
            imageIcon.getImage().getScaledInstance(
              widthConstraint, newHeight,
              Image.SCALE_SMOOTH )
         else
           // Create a resizing ratio.
           double ratio = (double) imgHeight / (double)
            heightConstraint;
           int newWidth = (int) ( (double) imgWidth / ratio );
           adjustedImg = new ImageIcon(
           imageIcon.getImage().getScaledInstance( newWidth,
              heightConstraint, Image.SCALE_SMOOTH )
         int resizeWidth = adjustedImg.getIconWidth();
         int resizeHeight = adjustedImg.getIconHeight();
         Panel p = new Panel();
         BufferedImage bi = new BufferedImage(resizeWidth, resizeHeight,
         BufferedImage.TYPE_INT_RGB);
         Graphics2D big = bi.createGraphics();
         big.drawImage(adjustedImg.getImage(), 0, 0, p);
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
         encoder.encode(bi);
         byte[] byteArray = os.toByteArray();
         return byteArray;
      else
      return new byte[0];
       }hope this helps.

  • Insert Image file from java to ms access database

    Are there any ways to insert image file or any files into microsoft access database and retrieve the file from the database. Guild will be helpful.Thank you.
    regards
    Singaravelan

    The right answer? Don't do it. You should not be putting images in any database.
    Better to write the image to the server's file system and add the path/link to the database instead.
    %

  • Insert/update image in Database from C:\ drive, In BLOB Field using PL/SQL

    is Any Body have a experience of Image file Saving, updating and getting from Table, i want to save it in Database not in any Folder or Link, its Urgent! i want to insert image in Table having BLOB field from C:\test.jpg

    Try the following link, some useful material :-
    http://www-rohan.sdsu.edu/doc/oracle/server803/A50580_2/img_uses.htm

  • Hashtable for multi part form to insert image and details to database:)

    Hey guys do you have any samples on using hashtable in multipart form to insert image as well as details into database?:)
    Oh it is because my form is using multipart from that enbales me to upload/Insert image into my database.
    Howerver, I also need to insert other details into my database such as productid, ProdName, unitprice.....
    Hence, My tutor suggested using hashtable.
    However, I do not understnd.
    Do you guys have any samples regarding on this?
    Thanks
    :D

    Cathy_Latte wrote:
    However, I do not understnd. More specifically: you do not understand how to use Maps? If so, just go through a book/tutorial on that subject. In fact you should have consulted your tutor or classmates for more information and you're here at a JSP/JSTL forum at the wrong place (you have a problem with Java in general, not with JSP), but OK, here's a link: [http://google.com/search?q=hashmap+tutorial+site%3Asun.com].

  • Insert Image and Load Image by VC# with Oracle 9i Database.

    I need save and load a Image to Database Oracle 9i, i use BLOB Datatype and VC#2003, i write code bellow:
    Load image data.
    m_Img is a parameter byte[], and :
    this.openFile.ShowDialog(this);
    string strFn=this.openFile.FileName;
    this.pcPerson.Image=Image.FromFile(strFn);
    FileStream fls;
    fls=new FileStream(@strFn,FileMode.Open,FileAccess.Read);
    m_Img=new byte[fls.Length];
    fls.Read(m_Img,0,System.Convert.ToInt32(fls.Length));
    fls.Close();
    //Add Parameter
    CnnOracle myBase = new CnnOracle();
    string reqSQL = "SP_PERSON_UPDATE";
    try
    OracleConnection myConn = myBase.OpenConnection(myBase.cnxString);
    OracleCommand myCommand = new OracleCommand(reqSQL,myConn);
    myCommand.Parameters.Add(new System.Data.OracleClient.OracleParameter("Faxno", System.Data.OracleClient.OracleType.NVarChar, 20));
    myCommand.Parameters["Faxno"].Value = myPerson.faxno;
    myCommand.Parameters.Add(new System.Data.OracleClient.OracleParameter("Email", System.Data.OracleClient.OracleType.NVarChar, 20));
    myCommand.Parameters["Email"].Value = myPerson.email;
    myCommand.Parameters.Add(new System.Data.OracleClient.OracleParameter("Photo", System.Data.OracleClient.OracleType.Blob));
    myCommand.Parameters["Photo"].Value = m_Img;
    myCommand.CommandType = CommandType.StoredProcedure;
    myCommand.ExecuteNonQuery();
    myBase.CloseConnection(myConn);
    catch(Exception myErr)
    throw(new Exception(myErr.ToString() + reqSQL));
    That code above don't run and have a error: "ORA-01460: unimplemented or unreasonable conversion requested\n",
    but i clear these row:
    myCommand.Parameters.Add(new System.Data.OracleClient.OracleParameter("Photo", System.Data.OracleClient.OracleType.Blob));
    myCommand.Parameters["Photo"].Value = m_Img;
    and modified StoreProcedure: clear parameter Photo, it run good
    Why? Help me, Please.
    Thank you very much.

    Can you post your table structure?

  • Saving images into database

    Hi All,
    I have a table with 3 BLOB columns to store images and a NUMBER type column to store the image id_no. I am using database 10g and Forms 6i
    My problem is I recently updated the database from 8i to 10g, and since then I am unable to update or insert the new images in these BLOB columns. When I update the existing image or insert new image record through forms, It does save the changes in existing or new record. But It does not show these images while query the record. and also does not give any error while executing the query in forms.
    But while trying to retrive the image from updated records or new record in reports, It throughs the error that image is format is unreadable or currupt.
    There wasn't any problem in 8i, i could update the record as many times I wanted or create as many records as needed.
    Is anybody have any clue about this problem! Any help in this regard will be highly appriciated.
    Thanking you and Best Regards.

    You should not save an image to database, since it'll make database slow, and difficult to write a web page to load image.
    Save an image to specific location, and save image location to database.
    Then, use <img> tag to call an image in web page.

  • Inserting images in Crystal Reports

    Hello,
    I have two questions regarding the use of pictures in a Crystal report :
    1. Is there a maximum dpi resolution limit for pictures to be inserted in a Crystal Reports.
    2. Is there a way to control the PDF output picture quality ? When exporting to PDF, the quality of the picture is reduced.
    Thank you
    Anthony

    I have the following questions about inserting images into Crystal Reports:
    1.  Can the images be positioned horizontally?
    2. When there is more that one image attached to a database record, can the number of images be limited in the report?
      (For example, limit the number of images for each record to two.)
    3. If there is more than one page to a record, how can the image for the record be suppressed on all pages subsequent to the first page of the report?
    4.  If there is no image attached to the database record, how the space reserved for the image closed up?
    Thank you.

Maybe you are looking for

  • Performance degradation after SP 24 installation

    Hi, Our SAP BI systems are upgraded to service pack 24. After this, we see a lot of performance degradation. (Process chains are taking time to complete in BI) Can anybody please suggest which note to apply to avoid this? Thx in advance. - V Sudhakar

  • Error while accessing role of a user

    hi , we received an error while scrolling a role assigned for the user. kindly see error msg and details displayed during that time. kindly assist. also how to Take a thread dump of the server node to find the blocking thread that causes the problem.

  • IPod NANO in watch mode v sleep mode.

    Hi Gang1 A quick one for you, I have recently taken to wearing my NANO as a watch, however, every time the screen blanks out (sleep mode?), when I turn it back on to check the time, the clock is gone and is replaced with a song title all ready to pla

  • Why Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException?

    Hello, In my netbeans generated swing code I get the following stacktrace: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException      at javax.swing.text.PlainView.updateMetrics(PlainView.java:188)      at javax.swing.text.PlainView.l

  • No help with broken screen

    I have read many articles on the internet about how wonderful and sypathetic Apple are when it comes to broken devices, and how people have had their devices replaced free of charge out of good will. Well, my son is nearly 8 years old and has owned a