This week's book giveaway is in the Flex forum.
We're giving away four copies of Flex 4 in Action and have Tariq Ahmed, Dan Orlando, John C. Bland II & Joel Hooks on-line!
See this thread for details.
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of Flex 4 in Action this week in the Flex forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JDBC
 
RSS feed
 
New topic
Author

regarding inserting any file

chandra reddy pandillapalle
Greenhorn

Joined: Mar 31, 2008
Messages: 6

Hi,
Any Body know how to insert any file into blob field.
Thanks,
Chandra
Jeanne Boyarsky
internet detective
Sheriff

Joined: May 26, 2003
Messages: 17162

Chandra,
You can use stmt.setBinaryStream() to pass the file contents into a statement.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]

"The set strikes me as something like the set of potatoes, radishes, farming, and lunch. " - a colleague's way of comparing both overlapping and disparate groups. made me laugh and thought of the ranch
chandra reddy pandillapalle
Greenhorn

Joined: Mar 31, 2008
Messages: 6

hi can you share the sample code

Thanks,
Chandra
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Messages: 1223

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.

Saifuddin..
[Linkedin] How To Ask Questions On JavaRanch My OpenSource
K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Messages: 96

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

Joined: Apr 20, 2006
Messages: 3028

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.

Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials]
Jeanne Boyarsky
internet detective
Sheriff

Joined: May 26, 2003
Messages: 17162

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.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]

"The set strikes me as something like the set of potatoes, radishes, farming, and lunch. " - a colleague's way of comparing both overlapping and disparate groups. made me laugh and thought of the ranch
 
jQuery in Action
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JDBC
 
RSS feed
 
New topic
IntelliJ open source