CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Location
    Fremont, CA
    Posts
    10

    Reading GIF file from the database

    Hello All,

    I want to create a new gif file by reading the data stored in the database that data is actually a gif file which is stored in a field which is of LONG RAW data type. How can i do this.
    Thanks in advance.

    Surendra


  2. #2
    Join Date
    May 1999
    Location
    Pune, MH, India.
    Posts
    453

    Re: Reading GIF file from the database

    Have u tried giving the data to ImageIcon. It has a constructor which takes byte array.

    - UnicMan
    http://members.tripod.com/unicman

  3. #3
    Join Date
    Oct 1999
    Posts
    2

    Re: Reading GIF file from the database

    If you accessing an Oracle database here some sample code that you can use. This code assumes you know how to get on an Oracle DB with JDBC already. Notice that this example uses the LONG RAW datatype. This is COMPLETELY different if you are using BLOB (Oracle 8+). If you ever intend to use Oracle replication the LONG RAW will not work ... oh well


    public String getLogo(String p_lcode){
    String l_name=null;
    InputStream l_gifdata=null;
    try{
    //Query the logo of the selected airline
    String l_query="select name,airline_logo from airline_long_raw_table where code="
    + "'" +p_lcode+ "'";
    // Create a statement object for executing the query
    Statement l_stmt = m_connection.createStatement();

    // Obtain the result-set for the selected airline record
    ResultSet l_result=l_stmt.executeQuery(l_query);

    if(l_result.next()){

    // Fetch column values
    l_name=l_result.getString(1); // Obtain the airline code

    // LONGRAW data can be accessed in two ways:
    // 1) By retrieving all the data at once (using getBytes method)
    // 2) By using streams. The LONGRAW data is made available to the program
    // as a stream, and the data can be retrieved chunk by chunk, which is
    // more eficient in terms of memory usage
    // In this sample we illustrate retrieval using streams method.
    l_gifdata=l_result.getBinaryStream(2);

    // Write the byte array into a local file
    FileOutputStream l_file=new FileOutputStream(l_name+".gif");

    int l_chunk=0;
    while((l_chunk = l_gifdata.read()) != -1)
    l_file.write(l_chunk);
    l_file.flush();
    l_file.close();
    l_result.close();//closing the resultset
    l_stmt.close(); //closing the statement object
    m_GUI.putStatus("Image obtained from database");
    }
    }catch(Exception ex){ //Trap IO Errors
    m_GUI.putStatus(ex.toString());
    }
    return l_name;
    }





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured