From: | john-paul delaney <jp(at)justatest(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Example Code breaks. |
Date: | 2002-04-29 09:20:38 |
Message-ID: | Pine.LNX.4.21.0204290719520.5669-100000@justatest.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
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.1 Documentation (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 one so 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
From | Date | Subject | |
---|---|---|---|
Next Message | Dave Cramer | 2002-04-29 11:42:28 | Re: Forward to another server (Forward para outro servidor) |
Previous Message | Chantal Ackermann | 2002-04-29 09:03:31 | Re: Forward to another server (Forward para outro servidor) |