Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

[3933] Retrieving Images from a Database

Last post 04-18-2007 6:58 AM by manoj3939. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 01-01-1999 12:00 AM

    [3933] Retrieving Images from a Database

    This thread is for discussions of Retrieving Images from a Database.

    • Post Points: 0
  • 01-21-2004 2:31 AM In reply to

    a question

    Hi Dave
    I was going thru your article on uploading and retreiving image from database. It was really good. My requirement is slightly different. When i retreive the image, i would like to display the image on the Image control in asp.net. How do i do that.
    Regards
    Ajay.
    • Post Points: 0
  • 02-29-2004 4:26 AM In reply to

    Useful, but...

    Yes, useful as far as it goes, but I would have hoped for:

    a. more information on contentypes

    b. a more complete discussion of the output options, for example displaying it in an image control, resizing it, etc.

    Perhaps a part II?

    John B
    • Post Points: 0
  • 03-18-2004 3:05 PM In reply to

    • osagie
    • Not Ranked
    • Joined on 03-18-2004
    • New Member
    • Points 5

    Help urgent!!!

    Hi
    I have a program code in java which is able to retrive and store information in text in a Access database but need the program to be able to do same for Images. Please can anyone help.

    Code Below

    import java.awt.image.*;
    import java.awt.*;
    import java.sql.*;
    import java.util.*;
    import javax.swing.*;

    public class Histogram extends JFrame {

       //JDBc driver name and database URL
       static final String driver= "sun.jdbc.odbc.JdbcOdbcDriver";
       static final String url="jdbcdbc:Histogram Database_1";

       //declare Connection and Statement for accessing and querying database
       private Connection connection;
       private Statement statement;

       //Constructor connects to database, quries database, processes
       //results and display results in window
       public Histogram()
       {
           super("Picture Table of Histogram Database_1");

       //connect to database Histogram and query database
       try{
           //load database driver class
           Class.forName(driver);

           //establish connection to database
           connection = DriverManager.getConnection(url);

           //create Statement for querying database
           statement = connection.createStatement();

           //query database
           ResultSet resultSet =
           statement.executeQuery("SELECT Filename FROM PictureTable");
    /////////////$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    //String CurrentFile = NULL;
    //Image image1.open(CurrentFile);
    //CurrentFile = statement.executeQuery("SELECT Filename FROM PictureTable WHERE PictureID=1");

    ////////////$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
           //process query result
           StringBuffer results = new StringBuffer();
           ResultSetMetaData metaData = resultSet.getMetaData();
           int numberOfColumns = metaData.getColumnCount();


           for(int i = 1; i <=numberOfColumns; i++ )
               results.append( metaData.getColumnName(i) + "\t");

           results.append("\n");


           while( resultSet.next()){
               
               for(int i = 1; i <=numberOfColumns; i++)
                   results.append( resultSet.getObject(i) + "\t");

               results.append("\n");
           }

           //set up GUI and display window
           JTextArea textArea = new JTextArea( results.toString() );
           Container container = getContentPane();

           container.add( new JScrollPane( textArea ) );
           
           setSize(300, 100 );
           setVisible(true);

           }

           //detect problem interacting with the database
           catch ( SQLException sqlException ) {
               JOptionPane.showMessageDialog ( null, sqlException.getMessage(),
               "Database Error", JOptionPane.ERROR_MESSAGE );

           System.exit(1);
           }

           //detect problem loading database driver
           catch ( ClassNotFoundException classNotFound ){
               JOptionPane.showMessageDialog ( null, classNotFound.getMessage(),
               "Driver Not Found", JOptionPane.ERROR_MESSAGE );

               System.exit(1);
           }

               //ensure statement and connection are closed properly
           finally{
               try{
                   statement.close();
                   connection.close();
               }

               //handle exception closing statement and connection
               catch ( SQLException sqlException ) {
                   JOptionPane.showMessageDialog( null, sqlException.getMessage(), "Database Error",
                   JOptionPane.ERROR_MESSAGE );

               System.exit(1);
               }
           }
       }//end Histogram Database_1

       //Lunch the application

       public static void main( String args[] )
       {
           //error found here
           Histogram window = new Histogram();
           window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
       }

       }//end class Histogram Database_1
       
    • Post Points: 0
  • 04-29-2004 12:04 PM In reply to

    Content Types

    How do you deal with Netscape 4 and other browsers that don't like showing images with .aspx extensions?  Is there a way to let these browsers know that that the content is infact a JPG?  I get this message:
    ------------------------------------

    Opening:
    image.aspx using netscape.exe.

    When you download a file from the network, you should be aware of security considerations.

    A file that contains malicious programming instructions could damage or otherwise compromise the contents of your computer.

    You should only use files obtained from sites that you trust.

    What do you want to do with this file?
    Open it
    Save it to disk

    ------------------------------------

    • Post Points: 0
  • 07-07-2004 4:14 AM In reply to

    • niros
    • Not Ranked
    • Joined on 07-07-2004
    • New Member
    • Points 5

    did you find a way?

    Hi, did you find a way to make it work they way you wanted?
    I am looking for a way to put it inside a controll as well.
    • Post Points: 0
  • 02-22-2005 1:49 AM In reply to

    • tadhg88
    • Not Ranked
    • Joined on 02-22-2005
    • New Member
    • Points 5

    Same Problem

    hey guys i have the exact same problem as ye have and im just wondering if ye managed to find a solution
    thanks in advance
    tadhg88
    • Post Points: 0
  • 11-15-2005 9:20 PM In reply to

    • Louie88
    • Not Ranked
    • Joined on 11-15-2005
    • New Member
    • Points 5
    Hi there! Try this „quite” simple fix. Thanks Dave, you helped a lot with this images mystery…

           <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
               AutoGenerateColumns="False" DataKeyNames="img_pk" DataSourceID="ImagesSqlDataSource" Width="627px">
               <Columns>
                   <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                   <asp:BoundField DataField="img_pk" HeaderText="img_pk" InsertVisible="False" ReadOnly="True"
                       SortExpression="img_pk" />
                   <asp:BoundField DataField="img_name" HeaderText="img_name" SortExpression="img_name" />
                   <asp:BoundField DataField="img_contenttype" HeaderText="img_contenttype" SortExpression="img_contenttype" />
                   <asp:TemplateField HeaderText="img_data" SortExpression="img_data">
                       <ItemTemplate>
                           <asp:Image ID="Image1" runat="server" ImageUrl='<%# Bind("img_pk", "ViewImage.aspx?img={0:d}") %>'></asp:Image>
                       </ItemTemplate>
                       <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text="Sorry, it can not be edited"></asp:TextBox>
                       </EditItemTemplate>
                   </asp:TemplateField>
               </Columns>
           </asp:GridView>




    • Post Points: 0
  • 11-25-2005 5:43 PM In reply to

    • Jud101
    • Not Ranked
    • Joined on 11-25-2005
    • New Member
    • Points 10

    can't get this to work

    I've been struggling to get an image to view on my webpage.  I had to make a few changes but no way would it work for me.  I ended up coping and pasting everything, ran into the error at this point : SqlDataReader dr = command.ExecuteReader();  which I thought there was a problem in doing a search based on an index number being an int value and not string.  I made the changes and the error went away but no image came out.  

    any help would be greatly appreciated.

    Judy
    • Post Points: 10
  • 12-14-2005 9:13 PM In reply to

    • tomk10
    • Not Ranked
    • Joined on 12-14-2005
    • New Member
    • Points 5
    Whar is Bind?  I've only seen DataBinder.Eval used here and your examp,le causes a Compilation Error.
    • Post Points: 0
  • 04-18-2007 6:58 AM In reply to

    • manoj3939
    • Not Ranked
    • Joined on 04-18-2007
    • India
    • New Member
    • Points 5

    Re: can't get this to work

    I am Facing the sam e problem, i am able to store an image into a database as image type but fetching from database in displaying it on a web page is not working.

    Fetching from the database is working fine it is not dispalying on a web page.

    can any body help me out from this problem.

    thanks

    Manoj

    Email me at :  manoj.it01@gmail.com

     

    • Post Points: 5
Page 1 of 1 (11 items)