From: | Sanjeev Rathore <intmail2002(at)yahoo(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | insert bytea type into PostgreSQL database |
Date: | 2002-07-30 01:11:03 |
Message-ID: | 20020730011103.73996.qmail@web21202.mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
I would like to insert bytea type of data into the
PostgreSQL database. On the prompt where database is
running I get an error that says: ERROR: Attribute
'image_data' is of type 'bytea' but _expression is of
type 'int4'.
Java class called ImageDb has this method that tries
to insert data into the table.
public void setImage(long imageId, long objId, String
imageName, BufferedInputStream bis , int imageSize,
String imageFor){
try{
String sqlText;
db.setAutoCommit(false);
sqlText = "insert into image(image_id, obj_id,
image_name, image_for, image_data) values(?, ?, ?, ?,
?)";
ps = db.prepareStatement(sqlText);
ps.setLong(1, imageId);
ps.setLong(2, objId);
ps.setString(3, imageName);
ps.setString(4, imageFor);
ps.setBinaryStream(5, bis, imageSize);
ps.executeUpdate();
ps.close();
db.setAutoCommit(true);
}catch(SQLException sqle){
System.out.println("ImageDb class threw
SQLException");!
System.out.println("It came from setImage(x,x,x,x)
method ");
sqle.printStackTrace();
}
}
Here is piece of the servlet called StorePostDone.java
that actually calls the method of ImageDb.java.
if(fileName != null){
long size = filePart.writeTo(dir);
long lImageSize = filePart.writeTo(dir);
int imageSize = (int)lImageSize;
long imageId = 21;
long objId = 43;
String imageName = filePart.getFileName();
file://FileInputStream fis = new
FileInputStream(filePart.getInputStream());
BufferedInputStream bis = new
BufferedInputStream(filePart.getInputStream());
imageDb.setImage(imageId, objId, imageName, bis,
imageSize, "sell");
As far as the table schema:
image_id, obj_id are bigint
image_for, image_name are varchar(50)
image_data is bytea
Does anybody know why I am not able to insert bytea
type data into the database.
Thanks,
Sanjeev Rathore
__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com
From | Date | Subject | |
---|---|---|---|
Next Message | William D. Tallman | 2002-07-30 01:17:30 | Migrating databases... |
Previous Message | Rob Brown-Bayliss | 2002-07-30 00:20:20 | Re: Questions about my strategy |