2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by musthafa.aj
0

try it...


1.I have declared the image datatype as OLE
2.Inserting the image code
--------------------------
PreparedStatement psmnt = con.prepareStatement("INSERT INTO IMAGESTORAGE(IMAGE) VALUES(?)");
File image = new File("Sunset.jpg");
FileInputStream fis = new FileInputStream(image)
psmnt.setBinaryStream(1, (InputStream)fis, (int)(image.length()));
int insertCount= psmnt.executeUpdate();
System.out.println(insertCount);
-------------------------------
3.retreival
Here iam reading and putting the image in a new file called "SunsetImageRead.jpg"
psmnt = con.prepareStatement("SELECT IMAGE FROM IMAGESTORAGE");
ResultSet rs = psmnt.executeQuery();
if(rs.next())
{
InputStream fis1;
FileOutputStream fos;
try
{
fis1 = rs.getBinaryStream("image");
fos = new FileOutputStream(new File("SunsetImageRead.jpg"));
int c;
while ((c = fis1.read()) != -1)
{
fos.write(c);
}
fis1.close();
fos.close();
}catch(Exception ex)
{
System.out.println(ex);
}//try-c

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.