• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding inserting any file

 
chandra reddy pandillapalle
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Any Body know how to insert any file into blob field.
Thanks,
Chandra
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
378
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chandra,
You can use stmt.setBinaryStream() to pass the file contents into a statement.
 
chandra reddy pandillapalle
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi can you share the sample code

Thanks,
Chandra
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi can you share the sample code


as Jeanne already point you the tip regarding your query. now its time to do some googling on your criteria.

Google is not so far from your mouse click.
 
K Kiran Kumar
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also use setBinaryStream() but there will be some limitations for that. I guess we cannot upload more than 4KB if we use setBinaryStream(). Any ways try out the following code...

org.apache.struts.upload.FormFile formfile=Fileinfo.getFile();
//The above step gets the formfile object from Fileinfo class.
PreparedStatement ps=null;
Connection con=Coredb.getConn();
try
{
String fileName=formfile.getFileName();
int fileSize=formfile.getFileSize();
byte bb[]=formfile.getFileData();

ps=con.prepareStatement("insert into fles values(?,?,?)");
ps.setString(1,fileName);
ps.setInt(2,fileSize);
ps.setBytes(3,bb);
}
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Muhammad Saifuddin:
as Jeanne already point you the tip regarding your query. now its time to do some googling on your criteria.


Muhammed, I understand that individuals should do their homework also they have to show some efforts, but at the same time being a new user (greenhorn) the OP might have been in a curiosity to ask further. They may not be really aware of the rules. We have to understand and respect that as well.

It would be better if we can point out to the links so that they can proceed further.

I believe you agree with me.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
378
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Raghavan. A link to the tutorial with some sample code is a long stretch from doing someone's homework.

I was in a rush when I posted my initial reply and didn't take the time to provide a proper link. So here it is.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic