• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inserting an Image into the DataBase :

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , Good day

Inserting an Image into the DataBase :

File image = new File( filename );
FileInputStream fis = new FileInputStream( image );
ps.setBinaryStream( 3, fis, ( int )image.length() )



The above code is for inserting an Image into DataBase , Now the qestion is that how can i pass this till the DAO Layer ?

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple. pass the image into a method of DAO class . and put your inserting stuff in that method
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Seetha ,
But i am not clear how to implement this from scratch . I just created database itself for this .

My scenario is like this :

I want to provide a Browse Button from the UI to enter a Image , from there on how can i achieve this (Pass this to the DAO )
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a search through this forum for file upload. This question gets asked a lot.
 
Sanjeev K Jain
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi,
There is no direct method to upload the file. But there are some open source projects are available like jakarta's common upload or UploadBean. Here are the steps to achieve file uploading
1) Declare the form type as FORM ENCTYPE='multipart/form-data'
2) Use any of the above API say you will use UploadBean in that case keep a variable in your bean of UploadedFile. e.g.

public class UploadImage{
private UploadedFile fileUpload;

......
create getters and setters...
}
Now you can use this variable for inserting into the database. Hope this helps.
Thanks,
Sanjeev
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic