Retrieve image from my sql database using jsp

I want to retrieve image from my sql (blob type) & save it in given relative path in server .(using jsp and servlets)
please give me some sample codes.

PreparedStatement pst = null;
  ResultSet rs=null;
pst = conn.prepareStatement("select image from imagedetails where imageid='"+imageid+"'");
rs=pst.executeQuery();
while(rs.next())
                            byte[] b=rs.getBytes("image");
                            FileOutputStream fos=new FileOutputStream("c://image.jpg");
                            fos.write(b);
                        } hi this the code to retrieve the image from DB and write to a file.

Similar Messages

  • Error while retrieving data from PL/SQL Table using SELECT st. (Urgent!!!)

    Hi Friends,
    I am using Oracle 8.1.6 Server, & facing problems while retrieving data from a PL/SQL Table:
    CREATE or REPLACE PROCEDURE test_proc IS
    TYPE tP2 is TABLE of varchar2(10); --declared a collection
    dt2 tP2 := tP2('a','b','c');
    i NUMBER(8);
    begin
    SELECT COUNT(*) INTO i FROM TABLE(CAST(dt2 as tP2));
    DBMS_OUTPUT.PUT_LINE('**'||i);
    end;
    While executing the above procedure, I encountered foll. error:
    ERROR at line 1:
    ORA-00600: internal error code, arguments: [15419], [severe error during PL/SQL execution], [], [],
    ORA-06544: PL/SQL: internal error, arguments: [pfrrun.c:pfrbnd1()], [], [], [], [], [], [], []
    ORA-06553: PLS-801: internal error [0]
    Can anyone please help me, where the problem is??
    Is it Possible to retrieve data from PL/SQL TABLE using SELECT statement? & How ?
    Thanks in advance.
    Best Regards,
    Jay Raval.

    Thanks Roger for the Update.
    It means that have to first CREATE TYPE .. TABLE in database then only I can fire a Select statement on that TYPE.
    Actually I wanted to fire a Select statement on the TABLE TYPE, defined & declared in PLSQL stored procedure using DECLARE TYPE .. TABLE & not using CREATE TYPE .. TABLE.
    I was eager to know this, because my organization is reluctant in using CREATE TYPE .. TABLE defined in the database, so I was looking out for another alternative to access PL/SQL TABLE using Select statement without defining it database. It would have been good if I could access a PLSQL TABLE using Select statement Declared locally in the stored procedure.
    Can I summarize that to access a PL/SQL TABLE using SELECT statement, I have to first CREATE TYPE .. TABLE?
    If someone have any other idea on this, please do let me know.
    Thanks a lot for all help.
    Best Regards,
    Jay Raval.
    You have to define a database type...
    create type tP2 is table of varchar2(10)
    CREATE OR REPLACE PROCEDURE TEST_PROC
    IS
    dt2 tP2 := tP2('a','b','c');
    i NUMBER(8);
    begin
    SELECT COUNT(*) INTO i FROM TABLE(CAST (dt2 AS tP2));
    DBMS_OUTPUT.PUT_LINE('**'||i);
    end;
    This will work.
    Roger

  • Display images from a SQL database

    I want to display images from a SQL database. The images are in a table under a specific column and are stored as a link to the image. How would I display the images from the column in LabVIEW?
    I'm using LabVIEW 2013 version 13 and SQL Server 2012
    Paul Power
    I have not lost my mind, it's backed up on a disk somewhere

    Hi PauldePaor,
    I hope you are well.
    Once you have pulled the data from the database into LabVIEW in a string form (or path), you can simply use the Read BMP File (Or jpg, png depending on the file type) VI.
    More information can be found here:
    http://digital.ni.com/public.nsf/allkb/02971A30F5D8FC6986256A0A004F11A0
    Kind Regards,
    Aidan H
    Applications Engineer
    National Instruments UK & Ireland

  • Generating next number from the SQL database using java

    Hi friends, I have a problem and need your help. I am working on a project about submitting claims form through the adobe PDF file and SQL database. I have problem working on a web service (written in java) that will generate the next Invoice Number from the SQL Database table. The field type for the column is text(var char). *Example: I first need to get into the table and search for the last Invoice number in the table and if the last invoice number in the table from the database is 3, i would want to generate the next number which is 4 and filled it up in the PDF file through web service that i am implementing. Can you all provide me some guidelines on how to implement this method in my web service?
    Thanks a lot. I need it by today. Hope someone can reply this as soon as possible.
    Lim89
    Edited by: LIM89 on Apr 2, 2008 7:10 PM

    far simpler to use a sequence generator, which most databases support.
    Suggested method to get the max value in the column is NOT secure, unless you lock the entire table for update before you do so, which is a severe performance penalty.

  • Inserting and retrieving data from a al32UTF8 database USING SQL Developer

    hi guys,
    Before i post my questions , i think its better for me to provide you guys with my understandings first so that it easier to understand where/if i have gone wrong..
    I am using Window XP and Oracle 10g
    Non-unicode client - a client program that need to use the OS code page for mapping of the retrieved unicode data from the database as well as the support of displaying/inserting the characters from that code page to the database.
    E.G sqlplusw.exe
    Therefore, when using a non-unicode client
    1) we have to set the OS code page (Control panel - regional and language setting - advance - language for non unicode program ) to the code page that contain the characters we are going to display/insert.
    2) we will also have to set the NLS_LANG characterset to the character set of the code page we are going to insert so that when we do a insert (for e.g in thai ) , oracle will know, and auto conversion to UNICODE can take place. This is also true when we retrieve unicode data from the database so that conversion to the correct character set can take place.
    INSERTING
    THAI ---> conversion ----> UNICODE
    RETRIEVING
    THAI <---- conversion <---- UNICODE
    I hope my basic understanding is correct up till this point.
    Unicode client - a client program that supports the displaying/inserting of unicode characters without the need of setting the OS code page (Control panel - regional and language setting - advance - language for non unicode program )
    E.G isqlplus http or SQL developer
    However,
    1) There is still a need to set the NLS_LANG so that correct conversion can take place between the client and the database.
    For e.g, when retrieving if we set the NLS_LANG character set to ZHS16GBK (chinese) and the data store in unicode in database is E.G (THAI) , then the conversion would be wrong .
    Since it is a unicode supported client, then the NLS_LANG character set should be set to UNICODE as well.
    Here come my questions
    *Important - please help if you are busy and have no other time to answer the rest of the questions
    *Q1) If i were to use a unicode client, what should i set my NLS_LANG character set to ?
    AMERICAN_AMERICA.UTF8 ?
    *Q2) Where do i set the NLS_LANG character set information in SQL Developer, i know there is a metalink for setting NLS_LANG using isqlplus but i cant seems to google any result for SQL developer.
    Q3) Is my basic understanding right until this point ? If not, please explain in a more generalised term as i am really not familiar with character sets, code page, unicode , glyphs and fonts..
    Q4) If a unicode client does not need to refer to the OS code page (set in regional and language) , is there a UNICODE code page for the client to refer to , or is there any Window API available ?
    Q5)
    There is still a need to set the NLS_LANG so that correct conversion can take place between the client and the >>database.
    For e.g, when retrieving if we set the NLS_LANG character set to ZHS16GBK (chinese) and the data store in >>unicode in database is E.G (THAI) , then the conversion would be wrong .am i right on this point for UNICODE supported client ?
    Thanks for spending time to read my questions and i hope to hear advices from you guys soon.
    Million thanks again for sharing.
    Best Regards,
    Noob but willing to learn

    The requirement to always set NLS_LANG is not true for JDBC, which ignores NLS_LANG altogether. Java programs fetch text data into String variables, which use Unicode UTF-16 by design. JDBC sets character set conversion so that data is converted between UTF-16 and the database or national character set.
    The requirement to set NLS_LANG is not generally true for OCI, either. The first call in an OCI problem can be OCIEnvNlsCreate(). This call has two parameters that allow the caller to define the character set to use for VARCHAR2/CHAR/LONG/CLOB/statement text and the character set to use for NVARCHAR2/NCHAR/NCLOB. Only if these character sets are specified as 0, NLS_LANG character set is used. Also, OCI programs can specify different character sets for each bind or define variable (i.e. input/output buffer). Note: OCI programs always use NLS_LANG to initialize the language and territory settings for the client program and the database session. Only the character set can be specified is OCIEnvNlsCreate().
    OCIEnvNlsCreate() can specify the client character set as UTF-16 (in platform endianess). This is not possible with NLS_LANG.
    Various interfaces building on OCI, such as Oracle ODBC and ODP .NET, explicitly initialize OCI with Unicode character set, and thus ignore the NLS_LANG character set as well.
    Thnx,
    Sergiusz

  • Retrieve data from MS Access database.

    Hi all,
    The following is part of my coding. Once I have clicked the jButton1, the jTextField1 will get the input of user and store into a variable named "bbb". After that the variable will be passed to a function as a parameter to retrieve data from MS Access database using the ResultSet method. Next, the ResultSet will be splited into many part and just the student ic will be displayed.
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
            String bbb = jTextField1.getText(); //get input from user and store into a variable named bbb
            ResultSet codes = getCodes(bbb); //Retrieve data from database
            Code c = getCode (codes); //split the retireved date to many part
             jLabel2.setText(c.ic);  //display the student ic only
       private static ResultSet getCodes(String bbb)
            Connection con = getConnection();
            try
            Statement s = con.createStatement();
            String select = "SELECT [Student-File].* " + "FROM [Student-File] WHERE (([Student-File].[student-code])=bbb); " ;
            ResultSet rows;
            rows = s.executeQuery(select);
            return rows;
            catch (SQLException e)
                System.out.println(e.getMessage());
            return null;
    private static Code getCode (ResultSet codes)
            try
                String name = codes.getString("student-name");
                String scode = codes.getString("student-code");
                String ic = codes.getString ("student-ic");
                String add = codes.getString ("student-address");
                String phone = codes.getString ("student-phone");
              return new Code (name,scode,ic,add,phone);
            catch (SQLException e)
                System.out.println(e.getMessage());
            return null;
        private static class Code
            public String name ;
            public String scode ;
            public String ic ;
            public String add;
            public String phone;
            public Code (String name, String scode, String ic,String add,String phone)
                this.name = name;
                this.scode = scode;
                this.ic = ic;
                this.add = add;
                this.phone = phone;
    }But after I have compiled the coding above, the following error existed.
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
    at testing3.getCode(testing3.java:137)
    [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
    at testing3.jButton1ActionPerformed(testing3.java:71)
    at testing3.access$000(testing3.java:17)
    at testing3$1.actionPerformed(testing3.java:45)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
    at java.awt.Component.processMouseEvent(Component.java:5488)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
    at java.awt.Component.processEvent(Component.java:5253)
    at java.awt.Container.processEvent(Container.java:1966)
    at java.awt.Component.dispatchEventImpl(Component.java:3955)
    at java.awt.Container.dispatchEventImpl(Container.java:2024)
    at java.awt.Component.dispatchEvent(Component.java:3803)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
    at java.awt.Container.dispatchEventImpl(Container.java:2010)
    at java.awt.Window.dispatchEventImpl(Window.java:1774)
    at java.awt.Component.dispatchEvent(Component.java:3803)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at testing3.getCode(testing3.java:137)
    at testing3.jButton1ActionPerformed(testing3.java:71)
    at testing3.access$000(testing3.java:17)
    at testing3$1.actionPerformed(testing3.java:45)
    My questions here are:
    1) Will my idea above work?
    2) Is it correct of my query statement that send to MS Access database?
    Can anyone help me?
    Thanks in advance,
    ning.

    you may try this:
    String select = "SELECT * FROM your_table_name WHERE your_column_name = '" + bbb + "'";or another approach using PreparedStatement:
    String select = "SELECT * FROM your_table_name WHERE your_column_name = ?";
    PreparedStatement ps = con.prepareStatement(select);
    ps.setString(1, "bbb");
    ResultSet rs = ps.executeQuery();hth.

  • How to store and retrieve blob data type in/from oracle database using JSP

    how to store and retrieve blob data type in/from oracle database using JSP and not using servlet
    thanks

    JSP? Why?
    start here: [http://java.sun.com/developer/onlineTraining/JSPIntro/contents.html]

  • Using Java to Retrieve Images from Oracle

    OracleResultSet.getCustomDatum method is deprecated. I was using this method to retrieve an ORDImage from an Oracle 9i database. What are developers using instead of getCustomDatum to retrieve images from the database. Thanks for all help in this matter.

    Hi use getBinaryStream(java.lang.String) or getBinaryStream(int) of java.sql.ResultSet for retrieving images from database
    Hope it will be useful
    regards
    chandru

  • How to store and retrieve images from database...

    Hi All
    Anubody tell me plz how to store images in database using jsp.
    and how to retrieve tme.
    Plz reply...
    Anurag

    Exactly
    try the links below may be those might help u in store and retrieval any kind of file.
    http://www.mysqltalk.org/insert-blob-example-vt112861.html
    https://java.sun.com/j2se/1.5.0/docs/guide/jdbc/blob.html
    http://javaalmanac.com/egs/java.sql/GetBlob.html
    http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.jdbc.doc/jdbc142.htm
    and a dearly advice friend please query google b4 you post any query out here.

  • JAVA, sqlserver - Need to load an image from the sql server database

    hi,
    I need to load an image from the sql server database using java. I have connected to the database and getting all other records except the records for a photo (datatype = LONGVARBINARY) and Remarks (datatype = LONGVARCHAR).
    I am using java and sql server db. The photo and remarks are stored in the db. and i need to show the image and the remarks fetching them from there.
    I get the error :
    Thread-9 org.hibernate.MappingException: No Dialect mapping for JDBC type: -1
    How can I achieve this?
    Thanks,
    Gargi

    Exactly. And are you using MySQL?
    No. You are using Microsoft SQL server if I have to believe your initial post. A quick google tells me that the dialect class to use is:
    org.hibernate.dialect.SQLServerDialect

  • Formating numbers in a form after retrieving from an SQL database

    Hello everyone,
    I am using php to populate a form using numbers taken from an sql database.  I am having a hard time showing decimal places in those numbers.  The code I am using in the value section of the form is:
    value="<?php if (isset($_POST['unit_price_1'])) {
         echo htmlentities( $_POST['unit_price_1'], ENT_COMPAT, 'UTF-8');
         } else {
              echo htmlentities($row_getInvoice['unit_price_1'], ENT_COMPAT, 'UTF-8');
         } ?>" />
    This code rounds all numbers up and eliminates decimal places.  I am trying to show dollars and cents.
    How do I alter the code to accomplish what I want.
    Jeff

    Not sure what might come in your way here, so I just made the following simple test by using a static value rather than one which gets derived from a recordset (the source shouldn´t matter), and this works well for me without seeing the value altered in any way:
    <?php
    $value = "10.22";
    ?>
    <input type="text" name="whatever" value="<?php echo htmlentities($value, ENT_COMPAT, 'UTF-8'); ?>" />
    However,. for displaying numeric values you really don´t need to use  htmlentities/ENT_COMPAT etc etc -- that´s something you´d rather use for displaying textual contents containg special characters like umlauts and such.
    If all you need is to add some degree of protection by escaping special HTML characters (<, >, &, etc.), the function htmlspecialchars() will only be escaping just these characters and leave the rest "as is", whereas htmlentities() is notably more rigi, because this function will convert all applicable characters to HTML entities -- but again: at this point you´re just *displaying* some numeric value, that is, such security measures are pretty much pointless in this scenario, because there´s nothing to protect from ;-)
    Please test what happens when doing away with the htmlentities - thing.
    Cheers,
    Günter

  • Stroing Image file in MS-SQL Database using Hibernate

    Hi, I am trying to store the image files(.jpg,.gif) into MS-SQL DB, and I have column type image in MS-SQL ,when I regenerate the Hibernate mapping it took as String, so Now problem is if I change to BLOB, its throwing excpetion that MS-SQL 2000 driver not support BLOB,
    I need some solution how to map and store the images in MS-SQL DB using Hibernate,
    It will hlpe lot.
    Thanks
    Srikanth

    Hi,
    Can any one help me solve out this problem?
    thanks
    Uma

  • Loading Image from MS SQL

    Dear All, i got problem when i get an image from MS SQL and tried to output it to jsp page. See anyone would help!
    Code segment for retrieve the image from MS SQL
    String a = "SELECT POSTER FROM PP WHERE IMDB='111'";
    ResultSet j = db1.executeQuery(a);
    InputStream in =null;
    while(j.next())
      in = j.getBinaryStream("POSTER");
    ServletOutputStream out = resp.getOutputStream();
    byte[] buf = new byte[1024];
    int len =0;
    while((len=in.read(buf))>=0)
        out.write(buf,0,len);
    in.close();
    out.close();
    j.close();
    db1.closeStatement();
    db1.closeConnection();1.when the program reach
    "in.read(buf)", it throws exception as below
    ***[SQLServer 2000 Driver for JDBC]Object has been closed.
    2. i debug the programe and observed the valuable "in" after
    code segment " in = j.getBinaryStream("POSTER");", i got this outline for the valuable "in"
    "in"=BaseInoutStreamWrapper(id=896204)
    ~ closed =false
    ~ isOutputStream=true
    ~ maxBytesReturn=2147483647
    ~numBytesReturn= 0
    ~numTotalBytesInStream=-1
    i was wondering the meaning for "numTotalBytesInStream=-1" is could not getting anything of the image from MS SQL ?
    Is anyone got idea about this?
    Many thanks for your attention.

    With any resultSet, it scrolls until calling next() returns false.
    At this point you are past the end of the record set - you have moved past the current record, and are not able to access it.
    You need to move your image processing code into the first while loop.
    In fact, I think you need to change that while loop to an if statement - there is only one record returned from this query?
    Conncetion con = null;
    Statment db1 = null;
    ResultSet j = null;
    try{
      String a = "SELECT POSTER FROM PP WHERE IMDB='111'";
      con = getConnectionFromSomewhere();
      db1 = con.createStatement();
      j = db1.executeQuery(a);
      // assume only one record is returned.               
      if (j.next()) {
        InputStream in = j.getBinaryStream("POSTER");
        ServletOutputStream out = resp.getOutputStream();
        byte[] buf = new byte[1024];
        int len =0;
        while((len=in.read(buf))>=0) {
          out.write(buf,0,len);
        in.close();
        out.close();
    finally{               
      if (j!= null) j.close();
      if (db1!= null) db1.closeStatement();
      if (con!= null) con.closeConnection();
    }

  • Error trying to run the Sample Code Virtual Private Database using JSP's

    Hi.
    I`ve downloaded the Virtual Private Database using JSP's example from the Oracle9iAS Security - Sample Corner (http://otn.oracle.com/sample_code/deploy/security/9i_security.html)
    I ran the SQL script just fine. I�ve Opened the JDeveloper Flile (security.jws) and tried to Make it (following step 2 on "Run the Application using JDeveloper Environmentinstructions" in the README ) but i get this error:
    Error: unable to copy to output directory, web.xml not found
    It seems that i need the web.xml to run this application, but in the zip file i cannot find any XML file.
    What can i do?.
    Thanks in advance for your help

    Hi,
    the problem seems not to be within your application but in missing files on your embedded OC4J. Just try and unzip the JDeveloper 10.1.3 install again.
    Frank

  • Question on retrieve image from mysql

    i want to retrieve image from mysql database and display on GUI
    can anyone tell me how to do
    Thank you

    You can use the JDBC API for Java Database Connectivity. With this you can obtain data from the database using Java. There is an excellent tutorial here at Sun.com: http://www.google.com/search?q=jdbc+tutorial+site:sun.com You can get the MySQL JDBC driver at their own site: http://www.google.com/search?q=download+jdbc+driver+site:mysql.com Get the most recent version which suits your environment. There is also good documentation available over there.
    For displaying in the UI, the approach differs per UI. As you didn't mention which UI you are using, I can't help you further in detail.

Maybe you are looking for

  • Old version of FreeHand 5

    I had a working version of FreeHand 5 on my XP machine, which I have used to do a great deal of work, mostly newsletters. It has a lot of features which seem to be missing in the MX versions. It stopped working when my backup disk failed. I need a ne

  • How do I hide txt on ios 7

    How do I hide the txt so it won't show what the other person txt me

  • IOS 5.1.1 - I have can no longer get my Exchange EMail

    Not sure what is going on, but I can no longer get my Exchange email. I can send to my self, but the email only shows on my laptop and not on my iPhone. Any help would be appreciated.

  • Same pdf is different in adobe reader en acrobat professional

    Hello, I have a slight problem with a PDF file. I have one pdf. When I open this pdf within Adobe Reader, everything looks fine, when i open exact the same PDF with acrobat professional, something weird is happening. The font't are changed. Also, som

  • Wireless Device User Interface

    Hello, I have developed JSPs and set up the Personalization Portal by creating a Service that runs off a Master Service. I can access the JSP without any problem, but on my wireless device which uses Windows CE, all my <SimpleMenuItem> tags appear as