Results 1 to 4 of 4
- 04-29-2009, 07:14 AM #1
- 04-29-2009, 11:22 AM #2
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
- 04-29-2009, 03:55 PM #3
Simplest way is to use a BLOB - Binary Long OBject. Check the API docs for the Java object and the SQL type of the same name.
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 04-30-2009, 09:28 AM #4
Similar Threads
-
How to insert large data into database using one insert query
By sandeepsai39 in forum New To JavaReplies: 3Last Post: 02-28-2009, 09:17 AM -
how to convert one format to another format
By mahipal_reddy621 in forum New To JavaReplies: 1Last Post: 12-02-2008, 10:21 AM -
MSAccess and hibernate
By bbq in forum JDBCReplies: 3Last Post: 04-30-2008, 04:38 PM -
How to retrieve HttpSession from axis 2.0.
By snooze-g in forum Advanced JavaReplies: 0Last Post: 10-02-2007, 07:08 AM -
how to retrieve the width of the column
By katie in forum New To JavaReplies: 1Last Post: 08-06-2007, 10:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks