【发布时间】:2012-07-08 18:38:36
【问题描述】:
我正在使用一个简单的界面(在 jsf 1.2 和 Rich faces 3.3.2,Oracle 11g R1 中)让用户使用 rich:fileUpload 选择图片并保存在表格中。 作为测试,我创建了下表。
CREATE TABLE TEST
(
MIME_TYPE VARCHAR2 (1000),
PHOTO BLOB,
STUDENT_ID NUMBER NOT NULL
)
将图片保存到BLOB字段的代码sn-p如下。
//......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
请问代码哪里出错了。
谢谢。
【问题讨论】:
-
SQL 类型 NUMBER 似乎与 Java 类型 Long 不兼容。
-
在 Oracle 中,LONG 是文本类型,而不是数字类型。这些答案中的大多数都在错误的地方寻找。