100分求答案,调试通过即结账,thin方式驱动oracle操作blob字段的问题 4300ORA-01461: 仅可以为插入 LONG 列的 LONG 值赋值 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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); 大哥。。longInput_modify.available()参数未定义。这是什么东东来的? 对了,我改掉了在你这应该是byte[] blobByte=new byte[is.available()]; is.read(blobByte); is.close(); 狂晕。。编译通过。出错:4300ORA-01461: 仅可以为插入 LONG 列的 LONG 值赋值请问公子是用thin方式驱动的oracle.还是没有用import oracle.sql.BLOB;import oracle.jdbc.*;而直接用import java.sql.*做的? thin是可以的存放blob的,推荐用thin。我的程序没遇到过你的这个问题晕too你的ORACLE是多少版本的 此程序的作用:向test(字段为name varchar2;b blob)库这个b的类型你确定是blob? 发我邮箱:[email protected]明天我给你测试一下, 8.1.6阿。能否看看全部写blob的源码,我是怕是我的环境的问题,在windows上和linux,hpunix上都是一样的问题. 恩。。因为我如果插入字符串入blob是成功的,麻烦哈。源码已发出。深表感谢 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(); }} 我的8.17上面测试成功你的路径写法有问题D:\\test\\Ora.java这个文件是一个图片了改成ora.jpg可以看你把连接的url,user和password改成你的就可以使用了OK 我绝望了,我再试试换个classes12.zip吧。 无缺公子,我把你的代码复制进去,改成我的连接。也遇到了上面的问题。还有,后来改了一些东西,正确了,但是只能读小文件,稍大一点,就错了。环境:windows2000 professional, jBuilder7, oracle8.1.7 to tmsheng 可以把你的代码发给我吗([email protected])?thx 关于struts1中如何取得表单form中数据的问题!!! 一个纠结的java试题,求指点 swt里面如何将一个图片平铺成一个新图片 使用commons-net.jar包怎么连接Windows server2003服务器? 一个求知者~ 很基础的很基础的一个编程.大哥们救救我啊! 如何去除JInternalFrame的标题栏 邮件附件(各种类型文件)的发送和接收问题.急待高手们来指点.. 哪里有焰火特效applet(随鼠标点击的版本)的源代码? java中有几个必要的环境变量要设置呀? java如何遍历一个目录,读出其中所有的文件名 applet很奇怪的问题。。。。
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);
byte[] blobByte=new byte[is.available()];
is.read(blobByte);
is.close();
4300ORA-01461: 仅可以为插入 LONG 列的 LONG 值赋值
请问公子是用thin方式驱动的oracle.
还是没有用
import oracle.sql.BLOB;
import oracle.jdbc.*;
而直接用import java.sql.*做的?
我的程序没遇到过你的这个问题
晕too你的ORACLE是多少版本的
明天我给你测试一下,
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();
}}
上面测试成功
你的路径写法有问题D:\\test\\Ora.java这个文件是一个图片了
改成ora.jpg可以看你把连接的url,user和password改成你的就可以使用了
OK
环境:windows2000 professional, jBuilder7, oracle8.1.7
可以把你的代码发给我吗([email protected])?thx