Hello List...
I'm trying to setup a servlet that posts images to a postgres table. Following the example code in the PostgreSQL
7.2.1Documentation (Chapter 8.6. Storing Binary Data) below I get an error:
setBinaryStream(int,java.io.InputStream,int) in java.sql.PreparedStatement cannot be applied to
(int,java.io.FileInputStream,long)
ps.setBinaryStream(4, fis, file.length());
^
Seems there's a mismatch of data types between int and long of InputStream and FileInputStream of java.io? How to cast
oneso it's type is compatible with the other?
Thanks for any suggestions
/j-p.
EXAMPLE CODE
To insert an image, you would use:
File file = new File("myimage.gif");
FileInputStream fis = new FileInputStream(file);
PreparedStatement ps = conn.prepareStatement("INSERT INTO images VALUES (?, ?)"
);
ps.setString(1, file.getName());
ps.setBinaryStream(2, fis, file.length());
ps.executeUpdate();
ps.close();
fis.close();
-----------------------
JUSTATEST Art Online
www.justatest.com