BLOB convertion into jpg

Hello,
I have asked about this before but I still haven't got it to work. The problem is getting a BLOB from oracle and then converting it into a .jpg file. My program only returns an empty file. If someone knows what's wrong with my code please let me know!
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;
import java.math.BigDecimal;
import java.util.Map;
import java.io.*;
class InsertImage {
public static void main (String args [])
throws SQLException, IOException {
String user, pass, snum, namer;
int enumber;
user = "xxx";
pass = "xxxxxx";
     // Connect using the jdbc driver.
     DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver ());
     //get the connection to the ccdb database.
     OracleConnection conn = (OracleConnection)
     DriverManager.getConnection("jdbc:oracle:thin:@cactus.prism.gatech.edu:1525:ccdb",user,pass);
conn.setAutoCommit(false);
Statement stmt = conn.createStatement ();
String cmd = "select * from ImageTable";
ResultSet rset = stmt.executeQuery(cmd);
System.out.println("Select statement executed");
FileOutputStream outFile=null;
while(rset.next()){
//get the Blob locator
System.out.println("Entering the loop ");
String count = ((OracleResultSet)rset).getString(1);
BLOB blob = ((OracleResultSet)rset).getBLOB(2);
outFile = new FileOutputStream("vaf.jpg");
//get ready to accept binary file
int chunk = blob.getChunkSize();
System.out.print("The chunk size is " + chunk);
byte buffer[]= new byte[chunk];
int length;
InputStream instream = blob.getBinaryStream();
// Fetch data
while ((length = instream.read(buffer)) != -1) {
     outFile.write(buffer, 0, length);
outFile.close();

Hi Pal...
Do something like this....
//assuming that you go the connection and PreparedStatement
String sQuery = "select picture_column from picture_table
where picture_id='photo1'";
pstmt = dbConnection.prepareStatement(sQuery);
rs = pstmt.executeQuery();
if(rs.next())
InputStream in= rs.getBinaryStream(1);
//assuming you are saving the picture on root directry of drive D
FileOutputStream FOS =new FileOutputStream("d:\\photo1.jpg");
int iChunk;
while((iChunk = in.read()) != -1)
FOS.write(iChunk);
FOS.flush();
FOS.close();
in.close();
That should work and you have to catch the nesesory SqlExceptions and IOExceptions

Similar Messages

  • Create avatar: convert into jpg

    Hi all,
    I would like to let my website members to create their
    avatars. There will be a .swf file for them selecting the facial
    features, clicking the "save" button, converting and saving the
    outlook into .jpg file, storing the file path into the database
    My friend will do the flash file for selecting the facial
    features. I know the php/mySQL coding for communicating with the
    server and the database. But we don't know how to connect them. I
    have searched in google. But I can't find something is like what I
    want.
    Please help me. Tell me how made it works. Any
    information/tutorials/samples?
    Thanks in advance.

    using the LoadVars() class is the recommended way to have
    flash call a php script.

  • How convert to jpg picture into bmp ?

    Hi experts,
    I am trying to convert my jpg picture into bmp. for this i write one report but showing some
    TRANSFER WA_MIME1 TO DSN1.
    HERE IS MY FULL CODE PLZ HELP ME.
    REPORT  ZSE78_7.
    DATA: blob TYPE w3mimetabtype,
           blob_size TYPE w3param-cont_len,
           blob_type TYPE w3param-cont_type  .
    DATA:
         p_color_scheme      TYPE char20  ,
         p_labels_groupid    TYPE igs_label_tab,
         p_labels_category   TYPE igs_label_tab  ,
         p_data     TYPE     igs_data_tab,
         p_charttype     TYPE     char20,
         p_legend     TYPE     char20,
         l_igs_chart TYPE  REF TO cl_igs_chart ,
         l_igs_chart_engine TYPE  REF TO cl_igs_chart_engine,
         i_igs_image_converter TYPE REF TO cl_igs_image_converter,
         mime TYPE  w3mimetabtype,
         html TYPE  w3htmltabtype,
         html_line TYPE  w3html,
         l_msg_text(72) TYPE  c,
         l_url TYPE  w3url,
         l_content_length TYPE  i,
         l_content_type TYPE  w3param-cont_type,
         l_content_subtype TYPE  w3param-cont_type.
    CALL FUNCTION 'GUI_UPLOAD'
       EXPORTING
         filename                      = 'e:\katoch.jpg'
        filetype                      = 'BIN'
    *      HAS_FIELD_SEPARATOR           = ' '
    *      HEADER_LENGTH                 = 0
    *      READ_BY_LINE                  = 'X'
    *      DAT_MODE                      = ' '
    *      CODEPAGE                      = ' '
    *      IGNORE_CERR                   = ABAP_TRUE
    *      REPLACEMENT                   = '#'
    *      CHECK_BOM                     = ' '
    IMPORTING
        filelength                    = l_content_length
    *      HEADER                        =
       TABLES
         data_tab                      = mime
    EXCEPTIONS
        file_open_error               = 1
        file_read_error               = 2
        no_batch                      = 3
        gui_refuse_filetransfer       = 4
        invalid_type                  = 5
        no_authority                  = 6
        unknown_error                 = 7
        bad_data_format               = 8
        header_not_allowed            = 9
        separator_not_allowed         = 10
        header_too_long               = 11
        unknown_dp_error              = 12
        access_denied                 = 13
        dp_out_of_memory              = 14
        disk_full                     = 15
        dp_timeout                    = 16
        OTHERS                        = 17
    IF sy-subrc <> 0.
         MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CREATE OBJECT i_igs_image_converter .
    i_igs_image_converter->input = 'image/jpeg'.
    i_igs_image_converter->output = 'image/x-ms-bmp'.
    i_igs_image_converter->width = '100'.
    i_igs_image_converter->height = '100'.
    CALL METHOD i_igs_image_converter->set_image
       EXPORTING
         blob      = mime
         blob_size = l_content_length.
    CALL METHOD i_igs_image_converter->execute
       EXCEPTIONS
         communication_error = 1
         internal_error      = 2
         external_error      = 3
         OTHERS              = 4.
    IF sy-subrc = 0.
       CALL METHOD i_igs_image_converter->get_image
         IMPORTING
           blob      = blob
           blob_size = blob_size
           blob_type = blob_type.
       DATA dsn1(20) TYPE c VALUE 'E:\test.bmp'.
    DATA wa_mime1 TYPE w3mime.
    *DATA wa_mime1 TYPE w3mimetabtype.
       OPEN DATASET  dsn1   FOR OUTPUT IN BINARY MODE.
       LOOP AT blob INTO wa_mime1.
         TRANSFER wa_mime1 TO dsn1.
         CLEAR wa_mime1.
       ENDLOOP.
    MESSAGE ' successfull' TYPE 'I'.
       CLOSE DATASET dsn1.
    ELSE.
       DATA: num TYPE i, message TYPE string.
       CALL METHOD i_igs_image_converter->get_error
         IMPORTING
           number  = num
           MESSAGE = message.
    MESSAGE 'not successfull' TYPE 'I'.
    ENDIF.

    HI
    i already converted it in binary form but when i transferring it to binary mode it generate error.
    the code is like this.
    LOOP AT blob INTO wa_mime1.
         TRANSFER wa_mime1 TO dsn1.
         CLEAR wa_mime1.
       ENDLOOP.
       CLOSE DATASET dsn1.

  • How can i convert CR2 images into jpg format, without iPhoto?

    i just import a lot of images with the format .CR2 to mac through "Image capture" is there an app to convert the frmat into .jpg, app like image capture or something like that?

    If Canons software doesn't work...?
    Try Snap Converter, File Juicer or Contenta Converter

  • How to convert BLOB data into string format.

    Hi,
    I have problem while converting blob data into string format.
    for example,
    Select dbms_lob.substr(c.shape.Get_wkb(),4000,1) from geotable c
    will get me the first 4000 byte of BLOB .
    When i using SQL as i did above,the max length is 4000, but i can get 32K using plsql as below:
    declare
    my_var CLOB;
    BEGIN
    for x in (Select X from T)
    loop
    my_var:=dbms_lob.substr(x.X,32767,1)
    end loop
    return my_var;
    I comfortably convert 32k BLOB field to string.
    My problem is how to convert blob to varchar having size more than 32K.
    Please help me to resolve this,
    Thanx in advance for the support,
    Nilesh

    Nilesh,
    . . . .The result of get_wkb() will not be human readable (all values are encoded into some binary format).
    SELECT utl_raw.cast_to_varchar2(tbl.geometry.get_wkt()) from FeatureTable tbl;
    -- resulting string:
        ☺AW(⌂özßHAA
    Å\(÷. . . .You may also want to have a look at { dbms_lob | http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#i1015792 } "The DBMS_LOB package provides subprograms to operate on BLOBs, CLOBs, NCLOBs, BFILEs, and temporary LOBs."
    Regards,
    Noel

  • Problem converting a batch of RAW's into jpg's

    I want to convert 200 RAW's into jpg's. been doing that for years but recently upgraded to Photoshop CC.
    When I run the imageprocessor it opens the first photo in Camera RAW and that's all, nothing happens...

    Moving to Photoshop forum.

  • Last wish, preset converting RAW into JPG with more contrast, saturation & sharpening

    A close family member is dying and she has still many RAW files, which of course look slightly lifeless as all RAW files do. She asked me to look for a simple Lightroom preset which will convert her RAWs into Jpgs with more contrast, saturation and sharpening. She has Lightroom 3, but has no experience in making presets and neither do I. She needs the preset to make the RAW files as Jpgs available to her partner & children. No fancy effects; just simple. She cannot work on her computer anymore. Can you help me with a concrete preset or if not can you make one for her?

    This forum is for plugin developers - consider posting in 'Photoshop Lightroom' forum instead (at top of page, New -> Discussion -> Photoshop Lightroom).

  • How to convert blob data into clob using plsql

    hi all,
    I have requirement to convert blob column into clob .
    version details
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE     11.1.0.7.0     Production
    TNS for 32-bit Windows: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production
    DECLARE
       v_blob      temp.blob_column%TYPE;------this is blob data type column contains  (CSV file which is  inserted  from screens)
       v_clob      CLOB; --i want to copy blob column data into this clob
       v_warning   NUMBER;
    BEGIN
       SELECT blob_column
         INTO v_blob
         FROM temp
        WHERE pk = 75000676;
       DBMS_LOB.converttoclob (dest_lob          => v_clob,
                               src_blob          => v_blob,
                               amount            => DBMS_LOB.lobmaxsize,
                               dest_offset       => 1,
                               src_offset        => 1,
                               blob_csid         => 1, -- what  is the use of this parameter
                               lang_context      => 1,
                               warning           => v_warning
       DBMS_OUTPUT.put_line (v_warning);
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.put_line (SQLCODE);
          DBMS_OUTPUT.put_line (SQLERRM);
    END;I am not getting what is the use of blob_csid , lang_context parameters after going the trough the documentation .
    Any help in this regard would be highly appreciated .......
    Thanks
    Edited by: prakash on Feb 5, 2012 11:41 PM

    Post the 4 digit Oracle version.
    Did you read the Doc for DBMS_LOB.CONVERTTOCLOB? - http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_lob.htm
    The function can convert data from one character set to another. If the source data uses a different character set than the target you need to provide the character set id of the source data.
    The blob_csid parameter is where you would provide the value for the source character set.
    If the source and target use the same character set then just pass zero. Your code is passing a one.
    >
    General Notes
    You must specify the character set of the source data in the blob_csid parameter. You can pass a zero value for blob_csid. When you do so, the database assumes that the BLOB contains character data in the same character set as the destination CLOB.
    >
    Same for 'lang_context' - your code is using 1; just use 0. It is an IN OUT
    >
    lang_context
    (IN) Language context, such as shift status, for the current conversion.
    (OUT) The language context at the time when the current conversion is done.
    This information is returned so you can use it for subsequent conversions without losing or misinterpreting any source data. For the very first conversion, or if do not care, use the default value of zero.

  • How to batch convert bmp files into jpg by dos command or c# program language?

    How to batch convert bmp files into jpg by dos command or c# program language?
    Many thanks for replying.

    Try
    GraphicsMagick.

  • How do I convert a JPG into PDF, Adobe converter not available in India yet ?!!!!!

    How do I convert a JPG into PDF, Adobe converter not available in India yet ?!!!!!

    Hi supersude,
    You can use Acrobat XI Pro software for converting jpg into pdf, Here's the download Link (Free 30 Days trial ) : https://helpx.adobe.com/acrobat/kb/acrobat-downloads.html
    You can buy the full version here : Adobe Store - Adobe Acrobat Professional XI
    Regards,
    Rahul

  • With Netscape all of the Webcam shots from live feeds were automatically saved in my cache folder and I could simply open my cache send the saved files into AcDsee and convert them into jpgs, It would save as many as I would allow space for. With firefox

    I cant retrieve my images from webcams that are cached any more with mozilla. With netscape all of the live webcam images from live cams were automatically saved in my cache folder and all i had to do was open it send the files to acdsee and turn them into jpgs. It would save them untill the Cache ran out of room no matter how many files or sites I had running. Mozilla seems to save what it wants when it wants and often dose not save any that I can retrieve because I believe it is bulking them into Cache 123 or 4 and those i cant open to retrieve the files. Sometimes it saves 100 or so and sometimes 2 or 3 sometimes 10 or more but i don't seem to have any control over what it does or does not save to retrieve no matter how much space i allow for the cache to save.
    == This happened ==
    Every time Firefox opened
    == I finally gave up trying to keep netscape due to all the ridiculess popups and continued reminders from you saying i had to switch over

    You have or had an extension installed (Ant.com Toolbar) that has changed the user agent from Firefox/3.6.3 to Firefox/3.0.12.
    You can see the Firefox version at the top and the user agent at bottom of the "Help > About" window (Mac: Firefox > About Mozilla Firefox).
    You can check the '''general.useragent''' prefs on the '''about:config''' page.
    You can open the ''about:config'' page via the location bar, just like you open a website.
    Filter: '''general.useragent'''
    If ''general.useragent'' prefs are bold (user set) then you can right-click that pref and choose ''Reset''.
    See [[Web sites or add-ons incorrectly report incompatible browser]] and [[Finding your Firefox version]]
    See also http://kb.mozillazine.org/Resetting_your_useragent_string_to_its_compiled-in_default

  • Convert Webarchive Files into jpg Files.

    I am hoping someone can help with the above.
    I wish to download webarchive pictures and store them in my iPhoto Library.At the moment I cannot find a way of converting into the correct file type.
    Can someone HELP please.

    Hello Terence.
    Thanks for responding.
    I have downloaded pictures of cars from the Auto Trader website.These have been saved as Webarchive Files in a Folder on my Desktop.When I click on them they open in Safari for viewing , no problem.
    I am trying to transfer and store them in my iPhoto Library for possible editing/printing as normal photos.
    Regards Colin.

  • How to convert RAW into jpgs?

    I used to use Capture One by Phase One to process my RAW images into jpgs, when I had WinXP on my pc. With my new computer, it has the new 64 bit, with Win Vista. Now, using Capture One is a total joke. You can't possibly get anything done.
    How can I use Photoshop CS4 to process RAW images into jpgs? I don't see a way that I can apply changes on one image, to others in a particular group. With Capture One when it was good on WinXP, I could make changes to one, lighten/brighten, sharpen, change the color temp, etc., apply it to all the desired images, then click to output a certain size, say 5x7 at 200 ppi, hit the button, and it would do it. I don't see that I can do any of that in Photoshop, short of using the ever-annoying set and action, then automate.
    Also, for professional work, where I'm processing hundreds of images at a time, is there other software I should look at, like Lightroom, Gimp, etc.?

    jeff bach wrote:
    How can I use Photoshop CS4 to process RAW images into jpgs?
    Use Bridge and Camera Raw:  Navigate Bridge to the folder with your raw files.  In Bridge, select/highlight the images you wish to process and save, then Open in Camera Raw (File > Open in Camera Raw, or Ctrl-R, or right click and Open in Camera Raw from context menu). Your selected raw images will open in camera raw in Filmstrip view.  Make any desired camera raw adjustments then, still in camera raw, do Select All then at bottom Save Images...  which will bring up a save options box in which you can choose jpegs or tff, where to save, and other options.
    With Capture One when it was good on WinXP, I could make changes to one, lighten/brighten, sharpen, change the color temp, etc., apply it to all the desired images, then click to output a certain size, say 5x7 at 200 ppi, hit the button, and it would do it. I don't see that I can do any of that in Photoshop, short of using the ever-annoying set and action, then automate.
    There are several ways to make changes to one image in camera raw then apply the changes to other raw image files.  In camera raw filmstrip mode, select the images you want to apply an adjustment to then apply the adjustment to the first of those images and it will be applied to all the others that are selected.  Or apply adjustments to the first image of a series then add additional selections and use camera raw's Synchronize.  Or, make adjustments to first image in series then click done, which will return you to Bridge.  In Bridge, select the image you want to copy camera raw adjustments from then Develop Settings > Copy Settings.  Select all the target images that you want to receive these settings then Develop Settings > Copy Settings.  Both Copy settings and ACR's Synchronize will bring up a selection box where you can check which settings you want to copy.
    You can select save ppi in camera raw.  You can use Camera Raw's crop function can get files to a desired aspect ratio if they are not already there.  Crop can be copied to other files via Synchronize or Develop settings - Copy if that is useful.  Getting a specific size in pixel dimensions may take another step.  Camera Raw offers a limited set of file sizes (in its Workflow Options).  If you want other than these, then one methodis to save images from Bridge using Photoshop's image processor.  After making camera raw adjustments and returning to Bridge, select desired raw images then Tools > Photoshop > Image Processor...  Set size and output options in the image processor.

  • Converting raw images into .jpgs.

    I took some pictures with my Canon 5D, using the camera's raw format. They turned out to be about 14MB. However, when I converted them to .jpgs, using Photoshop CC, they were only about 4MB. I needed to have .jpgs about 10 MB. How do I do that? I made them the highest quality, etc. I still could only get about 4MB in size. Do I have to lose all that data just by converting them to .jpg? Thank you for any help!

    file size in MB is a very poor criterion for judging image quality because reduction in file size is very dependent upon the original image content.
    Compare a complex multicolored photo converted to .jpg with an image (same original size) filled with pure white or gray or black; then compare the .jpg sizes.
    As indicated above, use .tif or other uncompressed (lossless) file format to retain image quality....use .png if image needs to keep transparency.
    Consider using camera settings to produce both raw and .jpg images from same shot (too late for images already shot) and compare/use whichever suits your needs best. 
    There are many (many free) progs to convert various raw formats to .jpg; some better than others, all results will be at least slightly different.

  • Writing BLOB column into a csv or txt or sql  files

    Hi All,
    I am having a requirement where i have to upload a file from user desktop and place that file into a unix directory. For this i am picking that file into a table using APEX and then writing that file in unix directory using UTL_FILE.
    The problem which i am facing is that after this every line in my file is having ^M character at the end.
    For this i modified my BLOB column into a CLOB column and then also i am facing the same problem.
    Is there any way to get rid of this as i have to upload these csv or txt files into tables using sql loader programs. i can;t write any shell script to remove ^M character before uploading as this program will be merge with existing programs and then it will require lots of code change.
    Kindly Help.
    Thanks
    Aryan

    Hi Helios,
    Thanks again buddy for your reply and providing me different ways.... but still the situation is i can;t write any shell script for removing the ^M. I will be writing into a file from CLOB column.
    Actually the scenrio is when i am writing a simple VARCHAR columns with 'W' mode then it is working fine, but i have a BLOB column which stores the data in binary format so i am converting that column into CLOB and then writing it into file with 'W' mode but then i am getting ^M characters. As per your suggestion i have to then again run a program for removing ^M or i have to modify all my previous programs for removing ^M logic.
    I want to avoid all these, and just wanted a way so that while writing into a file itself it should not have ^M. Else i have to go for a java stored procedure for running a shell script from sql, and in this still i am having some problem.
    Thanks Again Helios for your time and help.
    Regards
    Aryan

Maybe you are looking for

  • Sync Windows Mobile Treo 750 with Vista 64 bit, FINALLY DID IT!

    I have just spent 3 hours trying to set up sync between my Treo 750 and my new Vista 64-bit computer.  Here's what I learned: You have to download the Windows Mobile Device Center and its update (that's why some people felt they were downloading twic

  • File names of images in IPhoto

    I have two questions. Does anyone know how to see the photo/file name of images loaded into IPhoto? Is there a setting that you can turn on to show the file name under each image? Secondly. While trying to find answers to the above question I did dis

  • Launching report from button in forms

    I have a report with a user input parameter that i need to launch from a button within oracle forms, inputting the url does not display the report because of the perameter is there another way? ive looked into the built ins but they seem overly compl

  • Why MS Silverlight player not working in ubuntu

    I have installed Novell Moonlight 2.3 plug-in in Ubuntu firebox 7.01 but it failed to play any Silverlight video. Any suggestion will be appropriated

  • OWSM 10g Custom step deployment

    I try to deploy a custom step in OWSM 10g. Does anyone know where should I put the custom.jar and how to deploy it?