Apologies if this is off-topic, I posted to the jdbc forum on sun with little response.
I always try www.jguru.com -- I used to answer a lot of questions there. I should go back...
I insert an image into a postgres db using the following code:> but don't know if it's possible to use the same inputstream.
URL urlImage = getServletContext().getResource( "/images/" + imageFilename);
URLConnection urlImageConn = urlImage.openConnection(); int urlImageLength = urlImageConn.getContentLength(); InputStream is = urlImage.openStream();
... and using a preparedStatement, pStmt.setBinaryStream(1, is, urlImageLength);
However I'd like to insert a second image into the same db record
Actually, I'm not entirely clear on when the stream is read. Either the PreparedStatement reads the stream immediately, or it reads the stream when you perform the execute(). I read the 1.4 JavaDoc and I'm still not convinced either way.
Just in case it doesn't read the stream until later, simply use another stream:
URL urlImage2 = getServletContext().getResource("second image");
URLConnection urlImageConn2 = urlImage2.openConnection();
int urlImageLength2 = urlImageConn.getContentLength();
InputStream is2 = urlImage2.openStream();pStmt.setBinaryStream(x, is2, urlImageLength2);
Don't forget to close your streams and URLConnections when you're done (i.e. in a finally block)!
-chris
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
