我使用一个简单的界面(在JSF1.2和rich faces 3.3.2,Oracle11g R1中)让用户使用rich:fileUpload选择图片并保存到表中。作为测试,我创建了以下表。
CREATE TABLE TEST
(
MIME_TYPE VARCHAR2 (1000),
PHOTO BLOB,
STUDENT_ID NUMBER NOT NULL
)将图片保存到BLOB字段的代码片段如下所示。
//......From the uploadFile Listener
public void listener(UploadEvent event) throws Exception {
...
item = event.getUploadItem();
...
StudentPhotoDAO dao = new StudentPhotoDAO();
dao.storePhoto(item.getData(),item.getContentType(),studentId);
...
}
//......From the PhotoDAO ..........................
public void storePhoto(byte data[],String mimeType, Long studentId){
{
...
ByteArrayInputStream bis=new ByteArrayInputStream(data);
String query = "update TEST set PHOTO = ? ,MIME_TYPE = ? where STUDENT_ID=?";
pstmt = conn.prepareStatement(query);
pstmt.setAsciiStream(1,(InputStream)bis,data.length);
pstmt.setString(2,mimeType.toString());
pstmt.setLong(3,studentId);
pstmt.executeUpdate();
}我得到以下错误:
java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column请问代码中的错误在哪里?
谢谢。
发布于 2012-07-09 19:10:49
您将student_id指定为number,它似乎映射到BigInteger。例如,参见this table。
要么您提供BigInteger,要么您需要更改student_id的类型。
发布于 2013-03-14 21:07:39
看看Oracle LONG type description:"LONG是一种用于存储字符数据的Oracle数据类型...“。在Oracle中,So LONG不是数字。这是条短信。
我认为你得到这个错误是因为这个:pstmt.setAsciiStream(1,(InputStream)bis,data.length);
尝试使用pstmt.setBinaryStream(int, InputStream, int)或pstmt.setBinaryStream(int, InputStream, long)。
发布于 2012-07-10 03:40:08
你在打电话给我
pstmt.setLong(3,studentId);并将列指定为
STUDENT_ID NUMBER NOT NULL文档是怎么说的:
试图将LONG数据类型中的值插入另一个数据类型。这是不允许的。
所以只需要这样做:
STUDENT_ID INTEGER NOT NULL
pstmt.setInt(3, studentId);https://stackoverflow.com/questions/11393786
复制相似问题