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

試圖將圖像插入數(shù)據(jù)庫(kù)得到 ORA-01460:未實(shí)現(xiàn)或不合

trying to insert image into database getting ORA-01460: unimplemented or unreasonable conversion requested error(試圖將圖像插入數(shù)據(jù)庫(kù)得到 ORA-01460:未實(shí)現(xiàn)或不合理的轉(zhuǎn)換請(qǐng)求錯(cuò)誤) - IT屋-程序員軟件開(kāi)發(fā)技術(shù)分享
本文介紹了試圖將圖像插入數(shù)據(jù)庫(kù)得到 ORA-01460:未實(shí)現(xiàn)或不合理的轉(zhuǎn)換請(qǐng)求錯(cuò)誤的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在嘗試將圖像插入數(shù)據(jù)庫(kù)并使用自動(dòng)增量 photo_id.

我的表格列是:

PHOTO_ID(主鍵),用戶名 (fkey),圖片,PICTURE_TITLE,喜歡

我的代碼是

公共類 UploadPhotoDao {公共 int insertPhoto(UploadPhotoBean uploadBean){連接 con = null;PreparedStatement ps = null;整數(shù)索引 = 0;最終字符串查詢=插入照片詳細(xì)信息(PHOTO_ID,用戶名,圖片,圖片標(biāo)題,喜歡)值(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, 新整數(shù)(0));index = ps.executeUpdate();}捕捉(SQLException e){e.printStackTrace();} 捕捉(FileNotFoundException e){//TODO 自動(dòng)生成的 catch 塊e.printStackTrace();} 捕捉(IOException e){//TODO 自動(dòng)生成的 catch 塊e.printStackTrace();}最后 {ConnectionUtil.closeQuitly(ps);ConnectionUtil.closeQuitly(con);}回報(bào)指數(shù);}}

我收到了錯(cuò)誤:

<上一頁(yè)>java.sql.SQLException: ORA-01460: 請(qǐng)求未實(shí)現(xiàn)或不合理的轉(zhuǎn)換

解決方案

InputStream.available() 返回的大小流(Javadocs 中有明確記錄).

您需要查詢文件的大小,而不是輸入流中的可用字節(jié)":

ps.setBinaryStream(2, fis, (int)file.length());

根據(jù)您的 JDBC 驅(qū)動(dòng)程序版本,您也可以使用

ps.setBinaryStream(2, fis, file.length());

setBinaryStream(int, InputStream, long) 是在 JDBC 4.0 中定義的,因此并非所有驅(qū)動(dòng)程序版本都實(shí)現(xiàn).setBinaryStream(int, InputStream, int) 是 JDBC 2.0(如果我沒(méi)記錯(cuò)的話),應(yīng)該在所有版本中都可用.

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.

這篇關(guān)于試圖將圖像插入數(shù)據(jù)庫(kù)得到 ORA-01460:未實(shí)現(xiàn)或不合理的轉(zhuǎn)換請(qǐng)求錯(cuò)誤的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周?chē)h(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動(dòng)生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫(kù))
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對(duì)象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 欧美a级成人淫片免费看 | 二区在线视频 | 久久精品一区二区视频 | 久久久www成人免费精品 | 久久精品免费 | 国产一区二区三区视频 | 免费一区二区三区 | 欧美一级片黄色 | 日产精品久久久一区二区福利 | 国产黄色大片在线观看 | 久久免费国产 | 亚洲乱码国产乱码精品精的特点 | 51ⅴ精品国产91久久久久久 | 高清一区二区视频 | 美女爽到呻吟久久久久 | 久久久视频在线 | 亚洲视频手机在线 | 国产精品久久久久久久白浊 | 精品国产乱码久久久久久老虎 | 国产精品日日做人人爱 | 欧美亚洲综合久久 | 亚洲午夜视频 | 国产精品国产三级国产aⅴ中文 | 亚洲一视频 | 日本成人毛片 | 午夜精品久久久 | 北条麻妃国产九九九精品小说 | 国产小视频在线 | 一区二区三区国产在线观看 | www.色午夜.com| 在线免费观看a级片 | 免费观看毛片 | 久久久久久国产一区二区三区 | 欧美中文字幕在线 | 国产精品久久久久永久免费观看 | 超碰成人免费 | 欧美另类视频在线 | 就操在线 | 波多野结衣先锋影音 | 黄色免费在线观看网址 | 99伊人 |