Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

storing an image into a database

 
swathi poondru
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I want to store an image in a database as well as retrieve the image from it.
Here is my code.


import java.io.*;
import java.sql.DriverManager;
import java.sql.*;
public class StoreImage
{
public static void main(String[] args) throws Exception
{
DriverManager.registerDriver(new com.mysql.jdbc.Driver());


Connection con;
con= DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");


PreparedStatement stmt= con.prepareStatement("update bigtab set image=? where no= 1");

File f = new File("picture.gif");
FileInputStream fis= new FileInputStream(f);
stmt.setBinaryStream(1, fis, (int)f.length());


System.out.println("Image length="+ f.length());
System.out.println("No of rows affected = " + stmt.executeUpdate());


}
}

But the code has been compiled as well as executed bt the output is here.
Image length = 33723
No of rows affected = 0

i dont know why the image is not storing in the database.
Please anyone solve my problem.Its very urgent.
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
and there have been many posts on here about blobs, do you want to see if any of them are any help.
 
Ivan Jozsef Balazs
Rancher
Posts: 979
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there an image where no=1 ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic