【问题标题】:ORA-01460: unimplemented or unreasonableORA-01460: 未实现或不合理
【发布时间】:2011-04-11 19:57:43
【问题描述】:

我尝试在 oracle 数据库中运行此查询,但不幸的是我收到此错误,请帮助我:(

java.sql.SQLException: ORA-01460: 未实现或不合理的转换请求 现在这个问题解决了,我还有一个例外: 我改变了这一行

 pstmt.setBinaryStream(7, fis, (int) file.length());

 pstmt.setBinaryStream(7, fis, (long) file.length());

线程“AWT-EventQueue-0”java.lang.AbstractMethodError 中的异常:oracle.jdbc.driver.OraclePreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V

对于文本文件没有问题,但是当我尝试上传 JPG 文件时收到此错误。

    PreparedStatement pstmt = 
                          conn.prepareStatement("INSERT INTO PM_OBJECT_TABLE( " +
                          "N_ACTIVITY_ID, V_NAME,N_SIZE, D_MODIFY,N_CATEGORY, N_NODE_ID ,O_OBJECT) " +
                          " VALUES ( ? , ? , ? , ? , ? , ? ,?)");
                pstmt.setLong(1, N_ACTIVITY_ID);
                pstmt.setString(2, file.getName());
                pstmt.setLong(3, file.length());
                java.util.Date date = new java.util.Date(); 
                java.sql.Date sqlDate = new java.sql.Date(date.getTime()); 
                pstmt.setDate(4,sqlDate);
                pstmt.setInt(5, N_CATEGORY);
                pstmt.setLong(6, N_NODE_ID);
                pstmt.setBinaryStream(7, fis, (int) file.length());
                pstmt.executeUpdate();            

【问题讨论】:

  • O_OBJECT 列的 Oracle 类型是什么?
  • javanna 我和这个人遇到了同样的问题herongyang.com/JDBC/Oracle-BLOB-setBinaryStream.html 但我尝试了所有这些我都遇到了问题~!
  • 您使用的是哪个版本的 oracle jdbc?类路径中 jar 的名称是什么?

标签: oracle oracle10g


【解决方案1】:

java.lang.AbstractMethodError: com.mysql.jdbc.ServerPreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V

要解决此问题,您需要更改对 setBinaryStream 的调用,以便最后一个参数作为整数而不是长整数传递。


在遇到同样的问题时,我在博客中找到了这句话

像上面的 PreparedStatement.setBinaryStream() 有三个重载方法

我们应该使用 setBinaryStream(columnIndex, InputStream, ((((((((((INT)))))))))

否则,这可能会导致错误

【讨论】:

    【解决方案2】:

    我也遇到了这个问题的代码,然后我突然得到了这个错误。

    我正在使用 Glassfish 3 运行 Netbeans 8.0.2 在 GlassFish\Glassfish\libs 文件夹中,我有 2 个 ojdbc 文件 ojdbc6.jar 和 ojdbc14.jar 似乎即使 ojdbc6 包含在项目库中,也加载了 ojdbc14。

    我停止 glassfish 将 ojdbc14.jar 重命名为 ojdbc14.jar.bak 然后清理并构建和部署项目。

    问题已解决。

    【讨论】:

      【解决方案3】:

      我通过以前的建议之一解决了我的问题:

      public String insertBineryToDB(long N_ACTIVITY_ID,int N_CATEGORY,long  N_NODE_ID ,FileInputStream fis , java.io.File file) {
          Statement statement;
          try {
              //conn.close();
             // N_ACTIVITY_ID, V_NAME,N_SIZE, D_MODIFY,N_CATEGORY, N_NODE_ID ,O_OBJECT
              PreparedStatement pstmt = 
                                    conn.prepareStatement("INSERT INTO PM_OBJECT_TABLE( " +
                                    "N_ACTIVITY_ID, V_NAME,N_SIZE, D_MODIFY,N_CATEGORY, N_NODE_ID ,O_OBJECT) " +
                                    " VALUES ( ? , ? , ? , ? , ? , ? ,empty_blob())");
      
      
      
      InputStream bodyIn = fis;
      
                      pstmt.setLong(1, N_ACTIVITY_ID);
                      pstmt.setString(2, file.getName());
                      pstmt.setLong(3, file.length());
                      java.util.Date date = new java.util.Date(); 
                      java.sql.Date sqlDate = new java.sql.Date(date.getTime()); 
                      pstmt.setDate(4,sqlDate);
                      pstmt.setInt(5, N_CATEGORY);
                      pstmt.setLong(6, N_NODE_ID);
                      //pstmt.setBinaryStream(7, bodyIn,(int) file.length());
                      pstmt.executeUpdate();
                      conn.commit();
      
          PreparedStatement stmt2 = conn.prepareStatement(" select O_OBJECT from PM_OBJECT_TABLE where N_ACTIVITY_ID = ? for update ");
          stmt2.setLong(1, N_ACTIVITY_ID);
          ResultSet rset = stmt2.executeQuery();
      
          FileInputStream inputFileInputStream    = new FileInputStream(file);
          rset.next();
          BLOB  image = ((OracleResultSet) rset).getBLOB("O_OBJECT");
      
          int bufferSize;
          byte[]  byteBuffer;
          int bytesRead = 0;
          int bytesWritten = 0;
          int totBytesRead = 0;
          int totBytesWritten = 0;
      
          bufferSize = image.getBufferSize();
          byteBuffer = new byte[bufferSize];
      
          OutputStream blobOutputStream = image.getBinaryOutputStream();
      
          while ((bytesRead = inputFileInputStream.read(byteBuffer)) != -1) {
            // After reading a buffer from the binary file, write the contents
            // of the buffer to the output stream using the write()
            // method.
              blobOutputStream.write(byteBuffer, 0, bytesRead);
              totBytesRead += bytesRead;
              totBytesWritten += bytesRead;
          }
        inputFileInputStream.close();
        blobOutputStream.close();
      
        conn.commit();
        rset.close();
        stmt2.close();
      
       String output =  "Wrote file " + file.getName() + " to BLOB column." +
                        totBytesRead + " bytes read." +
                        totBytesWritten + " bytes written.\n";
          return output;
      } catch (Exception e) {
          e.printStackTrace();
          return "Wrote file " + file.getName() + " to BLOB column failed." ;
      }
      }
      

      【讨论】:

        【解决方案4】:

        使用 java.sql.PreparedStatement.setBinaryStream(int parameterIndex, InputStream x) -- 2 个参数,而不是 3 个。

        【讨论】:

          猜你喜欢
          • 2020-06-28
          • 2012-06-17
          • 2015-10-14
          • 2018-08-23
          • 2011-12-29
          • 1970-01-01
          • 2014-12-15
          • 2021-07-15
          • 2015-09-18
          相关资源
          最近更新 更多