trying to insert image into database getting ORA-01460: unimplemented or unreasonable conversion requested error(试图将图像插入数据库得到 ORA-01460:未实现或不合理的转换请求错误)
问题描述
我正在尝试将图像插入数据库并使用自动增量 photo_id.
我的表格列是:
PHOTO_ID(主键),用户名 (fkey),图片,PICTURE_TITLE,喜欢
我的代码是
公共类 UploadPhotoDao {公共 int insertPhoto(UploadPhotoBean uploadBean){连接 con = null;PreparedStatement ps = null;整数索引 = 0;最终字符串查询=插入照片详细信息(PHOTO_ID,用户名,图片,图片标题,喜欢)值(PHOTO_ID_SEQUENCE.nextval,?,?,?,?)";尝试 {con = ConnectionUtil.getConnection();ps = con.prepareStatement(查询);ps.setString(1, uploadBean.getUsername());文件文件 =new File(uploadBean.getPicture());FileInputStream fis = new FileInputStream(file);ps.setBinaryStream(2, fis, fis.available());ps.setString(3, uploadBean.getPictureTitle());ps.setInt(4, 新整数(0));index = ps.executeUpdate();}捕捉(SQLException e){e.printStackTrace();} 捕捉(FileNotFoundException e){//TODO 自动生成的 catch 块e.printStackTrace();} 捕捉(IOException e){//TODO 自动生成的 catch 块e.printStackTrace();}最后 {ConnectionUtil.closeQuitly(ps);ConnectionUtil.closeQuitly(con);}回报指数;}}
我收到了错误:
<上一页>java.sql.SQLException: ORA-01460: 请求未实现或不合理的转换
InputStream.available()
不返回的大小流(Javadocs 中有明确记录).
您需要查询文件的大小,而不是输入流中的可用字节":
ps.setBinaryStream(2, fis, (int)file.length());
根据您的 JDBC 驱动程序版本,您也可以使用
ps.setBinaryStream(2, fis, file.length());
但 setBinaryStream(int, InputStream, long)
是在 JDBC 4.0 中定义的,因此并非所有驱动程序版本都实现.setBinaryStream(int, InputStream, int)
是 JDBC 2.0(如果我没记错的话),应该在所有版本中都可用.
I'm trying to insert an image into database and with auto increment photo_id.
my table columns are:
PHOTO_ID (primary key),
USERNAME (fkey),
PICTURE,
PICTURE_TITLE,
LIKES
my code is
public class UploadPhotoDao {
public int insertPhoto(UploadPhotoBean uploadBean){
Connection con = null;
PreparedStatement ps = null;
int index = 0;
final String query = "INSERT INTO PHOTOS_DETAILS (PHOTO_ID,USERNAME,PICTURE,PICTURE_TITLE,LIKES) VALUES (PHOTO_ID_SEQUENCE.nextval,?,?,?,?)";
try {
con = ConnectionUtil.getConnection();
ps = con.prepareStatement(query);
ps.setString(1, uploadBean.getUsername());
File file =new File(uploadBean.getPicture());
FileInputStream fis = new FileInputStream(file);
ps.setBinaryStream(2, fis, fis.available());
ps.setString(3, uploadBean.getPictureTitle());
ps.setInt(4, new Integer(0));
index = ps.executeUpdate();
}
catch (SQLException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
ConnectionUtil.closeQuitly(ps);
ConnectionUtil.closeQuitly(con);
}
return index;
}
}
I'm getting the error:
java.sql.SQLException: ORA-01460: unimplemented or unreasonable conversion requested
InputStream.available()
does not return the size of the stream (which is clearly documented in the Javadocs).
You will need to query the size of the file, not the "available bytes" in the inputstream:
ps.setBinaryStream(2, fis, (int)file.length());
depending on the version of your JDBC driver you can also use
ps.setBinaryStream(2, fis, file.length());
But setBinaryStream(int, InputStream, long)
is defined in JDBC 4.0 and thus not implemented by all driver versions. setBinaryStream(int, InputStream, int)
is JDBC 2.0 (if I'm not mistaken) and should be available in all versions.
这篇关于试图将图像插入数据库得到 ORA-01460:未实现或不合理的转换请求错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:试图将图像插入数据库得到 ORA-01460:未实现或不合
基础教程推荐
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 降序排序:Java Map 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01