jGuru
Register Email     Password Forgot your
password?
HOME FAQS FORUMS DOWNLOADS ARTICLES PEERSCOPE LEARN

  Search   jGuru Search Help

Question How can I insert images into a Mysql database?
Derived from A question posed by Sreenivas Kandikonda
Topics Java:API:JDBC:DBMS/Product Specific
Author Kasi Mono
Created Jan 31, 2002 Modified Jan 31, 2002


Answer
This code snippet shows the basics:
File file = new File(fPICTURE);
FileInputStream fis = new FileInputStream(file);
PreparedStatement ps = 
   ConrsIn.prepareStatement("insert into dbPICTURE values (?,?)");

// ***use as many ??? as you need to insert in the exact order*** 
ps.setString(1,file.getName());
ps.setBinaryStream(2,fis,(int)file.length());
ps.executeUpdate();
ps.close();
fis.close();


Is this item helpful?  yes  no     Previous votes   Yes: 5  No: 2



Comments and alternative answers

Comment on this FAQ entry

Insert images into database
Arjun VS, Oct 23, 2007
this code works fine. how is that we can insert an image from a remote system.

Is this item helpful?  yes  no     Previous votes   Yes: 0  No: 0



Reply to this answer/comment  Help  
Insert images into database
Arjun VS, Oct 23, 2007
this code works fine. how is that we can insert an image from a remote system.

Is this item helpful?  yes  no     Previous votes   Yes: 0  No: 0



Reply to this answer/comment  Help  


Ask A Question



 
Related Links

JDBC FAQ

JDBC Forum

Sun's JDBC pages

JDBC 2.0 optional package

Wish List
Features
About jGuru
Contact Us

 



The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers