aspose file tools*
The moose likes JDBC and the fly likes storing an image into a database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "storing an image into a database" Watch "storing an image into a database" New topic
Author

storing an image into a database

swathi poondru
Greenhorn

Joined: Mar 15, 2012
Posts: 1
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

Joined: Oct 21, 2008
Posts: 1107

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

Joined: May 22, 2012
Posts: 867
    
    5
Is there an image where no=1 ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: storing an image into a database