• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

how to store/retrive image in oracle database using struts 1.2

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

hello

i am uploading image from jsp.
can anybody tell me how to store image in oracle database using struts1.2?

as well please tell me how to retrive image from oracle database..?

thanking you
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use a BLOB to store the image in its byte form. You can use PreparedStatement in combination with FileInputStream for storing, and ResultSet in combination with FileOutputStream (or ByteArrayOutputStream for in-memory images) for retrieving.
 
hem raj
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many Thank Rob

i have done following code for saving image

FileInputStream fis;
File file;
String str="";

file=new File("C:/Image/tra8.jpg");
fis=new FileInputStream(file);
str= "Insert into Image values(1,'"+(int)file.length()+"')";

db.execute(str);
System.out.println("insert successfully");

the above code is inserting image....i don't know the above code is right or not.. but it insert record in table;

but i am not understanding how to retrive image on JSP..

what to write in Action Class to retrive image and On jsp page...??

 
Rob Spoor
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

hem raj wrote:Many Thank Rob

i have done following code for saving image

FileInputStream fis;
File file;
String str="";

file=new File("C:/Image/tra8.jpg");
fis=new FileInputStream(file);
str= "Insert into Image values(1,'"+(int)file.length()+"')";

db.execute(str);
System.out.println("insert successfully");

the above code is inserting image....i don't know the above code is right or not.. but it insert record in table;


It inserted a record alright, but not with the image. You gave the record two values: a 1, and the file length. That's two integer values, not the image itself. I said you should use a PreparedStatement; I don't see any.
 
hem raj
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Now is it Ok??

file=new File("C:/ImageUpload/tra8.jpg");
fis=new FileInputStream(file);
str= "Insert into Image values(?,?)";
pstmt = dbConnection.prepareStatement(str);
pstmt.setInt(1,1);

byte[] b= new byte[fis.available()+1];
fis.read(b);
pstmt.setBytes(2,b);
pstmt.execute();
 
Rob Spoor
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Available Doesn't Do What You Think It Does.

I was thinking about the following:
Don't forget to close() fis, preferably using a try-finally block.
 
hem raj
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello Rob,

I have done code for inserting image as per your instruction...


now what to do for retriving image on JSP..

what to write in Action Class to retrive image and On jsp page...??



hey Rob i have one question.....

before doing this i have tried for storing image on local disk....

it is working on my machine perfactly....
but when i am accessing from another machine the image is not coming.... then i got solution like on another machine first i have to access my machine from RUN....then i gave username/password for my machine .

and on my machine i have put folder of image in shared.

then it will allow and work perfactly...

but this solution is not good there for i am moving for storing image in database...

is there any posibility to access image from local disk without accessing (from RUN) my machine from client machine..?

and one thing is that i am working on windows environment... where as my deployment server is linux environment..

i am using jboss-4.0.4RC1 application server..


 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic