久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

試圖將圖像插入數據庫得到 ORA-01460:未實現或不合

trying to insert image into database getting ORA-01460: unimplemented or unreasonable conversion requested error(試圖將圖像插入數據庫得到 ORA-01460:未實現或不合理的轉換請求錯誤) - IT屋-程序員軟件開發技術分享
本文介紹了試圖將圖像插入數據庫得到 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:未實現或不合理的轉換請求錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 欧美日韩在线高清 | 91免费高清| 亚洲综合色视频在线观看 | 免费观看一级视频 | 日韩欧美中文 | 亚洲成人精品 | 99精品免费久久久久久久久日本 | 荷兰欧美一级毛片 | 在线观看精品视频网站 | 日韩综合在线 | 国产丝袜一区二区三区免费视频 | 久久国产成人午夜av影院武则天 | 一区二区免费视频 | 免费观看一级特黄欧美大片 | 欧美三级不卡 | 免费久久99精品国产婷婷六月 | 精品久久国产老人久久综合 | 久久久久国产一区二区三区四区 | 四虎在线观看 | 三级黄色片在线播放 | 久久这里有精品 | 免费一级大片 | 久久久久久亚洲精品 | 欧美一二区 | 日韩视频精品在线 | 国产一区999 | 午夜av电影 | 91精品久久久久久久久久 | 婷婷99| 91av在线影院 | 丝袜 亚洲 另类 欧美 综合 | 国产性生活一级片 | 婷婷91| 免费看国产a | 亚洲一区二区三区乱码aⅴ 四虎在线视频 | 久久久久久免费毛片精品 | 在线免费观看视频黄 | 成人免费影院 | 国产精品久久久久久久久免费高清 | 日本久久网| 亚洲精品黄色 |