java.sql.SQLException:ORA-01461:只能为插入到LONG列而绑定LONG值 [英] java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column

查看:157
本文介绍了java.sql.SQLException:ORA-01461:只能为插入到LONG列而绑定LONG值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个简单的界面(在jsf 1.2和Rich Faces 3.3.2中,Oracle 11g R1)让用户选择带有rich:fileUpload的图片并将其保存在表中. 作为测试,我创建了下表.

I am using a simple interface (in jsf 1.2 and rich faces 3.3.2, Oracle 11g R1) to let user select picture with rich:fileUpload and save in a table. As a test, i created following table.

CREATE TABLE TEST
(
 MIME_TYPE VARCHAR2 (1000),
 PHOTO BLOB,
 STUDENT_ID NUMBER NOT NULL
)

将图片保存到BLOB字段的代码段如下.

code snippet to save the picture to BLOB field is as follows.

//......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

代码中的错误在哪里?

谢谢.

推荐答案

您将student_id指定为number,它似乎映射到BigInteger.参见例如此表.

You specify the student_id as number, which seems to map to BigInteger. See e.g. this table.

要么提供BigInteger,要么需要更改student_id的类型.

Either you supply a BigInteger or you need to change the type of student_id.

这篇关于java.sql.SQLException:ORA-01461:只能为插入到LONG列而绑定LONG值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆