4300ORA-01461: 仅可以为插入 LONG 列的 LONG 值赋值

解决方案 »

  1.   

    InputStream is=new FileInputStream(file);//创建输入流,将外部文件输入到InputStream 中。这一句后面你再加上
     byte[] blobByte=new byte[longInput_modify.available()];
      is.read(blobByte);
      is.close();pstmt.setBinaryStream(2,is,(int)file.length());改成
    pstmt.setBinaryStream(2,(new ByteArrayInputStream(blobByte)), blobByte.length);
      

  2.   

    大哥。。longInput_modify.available()参数未定义。这是什么东东来的?
      

  3.   

    对了,我改掉了在你这应该是
    byte[] blobByte=new byte[is.available()];
      is.read(blobByte);
      is.close();
      

  4.   

    狂晕。。编译通过。出错:
    4300ORA-01461: 仅可以为插入 LONG 列的 LONG 值赋值
    请问公子是用thin方式驱动的oracle.
    还是没有用
    import oracle.sql.BLOB;
    import oracle.jdbc.*;
    而直接用import java.sql.*做的?
      

  5.   

    thin是可以的存放blob的,推荐用thin。
    我的程序没遇到过你的这个问题
    晕too你的ORACLE是多少版本的
      

  6.   

    此程序的作用:向test(字段为name varchar2;b blob)库这个b的类型你确定是blob?
      

  7.   

    发我邮箱:[email protected]
    明天我给你测试一下,
      

  8.   

    8.1.6阿。能否看看全部写blob的源码,我是怕是我的环境的问题,在windows上和linux,hpunix上都是一样的问题.
      

  9.   

    恩。。因为我如果插入字符串入blob是成功的,麻烦哈。源码已发出。深表感谢
      

  10.   

    package demo;import java.sql.*;
    import java.io.*;
    import oracle.sql.BLOB;
    import oracle.jdbc.*;//此程序的作用:向test(字段为name varchar2;b blob)库,插入一个文件(read.txt),再将其从库中读出,写到ok.txt中public class orablob
    {
      public void orablob()
    {}
      public static void insertblob()
      {
      try
      {
    //首先是将文件输入到数据库。
        Class.forName("oracle.jdbc.driver.OracleDriver");//注册数据库引擎。
        Connection conn= DriverManager.getConnection("dburl=jdbc:oracle:thin:@yf:1521:kjb", "kjb", "KJBMostJ2EEOraDB");//建立连接串
        conn.setAutoCommit(false);//关闭自动提交,以提高性能。
        Statement stmt=conn.createStatement();//建立会话
       
       try
       {
         stmt.execute ("drop table test");
       }
       catch (SQLException e)
       {
         // An exception could be raised here if the table did not exist already.
       }
      stmt.execute ("create table test (fname varchar2(600),bx blob)");    File file=new File("D:\\test\\Icon.jpg");
        InputStream is=new FileInputStream(file);//创建输入流,将外部文件输入到InputStream 中。
        System.out.print(file.length());
        byte[] blobByte=new byte[is.available()];
       is.read(blobByte);
       is.close();
        PreparedStatement pstmt=conn.prepareStatement("INSERT INTO TEST  VALUES (?,?)");
        pstmt.setString(1,file.getName());
        pstmt.setBinaryStream(2,(new ByteArrayInputStream(blobByte)), blobByte.length);
        pstmt.executeUpdate();//将文件流插入到数据库中。
        pstmt.close();//以下是从库中读取文件。
        ResultSet rset=stmt.executeQuery("SELECT * from test");
        while (rset.next())
          {// Get LOB locators into Java wrapper classes.
            BLOB blob=((OracleResultSet)rset).getBLOB(2);//获取文件字段。
            // int chunk=blob.getChunkSize();
           int chunk=blob.getChunkSize();
          byte [] buffer=new byte[chunk];
            System.out.println(chunk);        File binaryFile=new File("D:\\test\\Ora.java");
            FileOutputStream fileoutstream=new FileOutputStream(binaryFile);//创建文件输出流。
            InputStream instream=blob.getBinaryStream();//建立输入流,并将字段comment的值以流的形式,放入instream变量。
            instream.read(buffer,0,chunk);//将文件流存入变量buffer,以buffer为中转
            fileoutstream.write(buffer,0,chunk);//将buffer写入文件输出流。
            System.out.println("write ok!");
            instream.close();//关闭流
            fileoutstream.close();
          }
        rset.close();
        stmt.close();
        conn.close();
        System.out.print("ok");
      }
      catch(Exception ee)
      {
          System.out.println(ee.getMessage());
      }
      }
          public static void main(String args[])
        {
         insertblob();
    }}
      

  11.   

    我的8.17
    上面测试成功
    你的路径写法有问题D:\\test\\Ora.java这个文件是一个图片了
    改成ora.jpg可以看你把连接的url,user和password改成你的就可以使用了
    OK
      

  12.   

    我绝望了,我再试试换个classes12.zip吧。
      

  13.   

    无缺公子,我把你的代码复制进去,改成我的连接。也遇到了上面的问题。还有,后来改了一些东西,正确了,但是只能读小文件,稍大一点,就错了。
    环境:windows2000 professional, jBuilder7, oracle8.1.7
      

  14.   

    to tmsheng
     可以把你的代码发给我吗([email protected])?thx