在oracle中更新BLOB字段出现问题. 有问题吧?len都没有初始化:int len;{ outs.write( buf , 0 , len );} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不好意思,int len;下有个whileBLOB b = ( BLOB )dr.getItem( 0 );OutputStream outs = b.getBinaryOutputStream();ByteArrayInputStream bais = new ByteArrayInputStream( com.system.util.util.BASE64Decoder( dm.getParams().get( paramName ).getValue() ) );byte[] buf = new byte[ b.getChunkSize() ];int len;while( ( len = bais.read( buf ) ) != -1 ){ outs.write( buf , 0 , len );}outs.flush();outs.close();bais.close(); 我用过Clob大字段,不过也只是读里面的数据,没写过 我在写入BLOB字段是也遇到了同样的问题,更主要的是,在存入的数据大于2K时,无法正常读出 替换CLOB对象(将原CLOB对象清除,换成一个全新的CLOB对象),详细信息请参考:http://www.s8s8.net/ipb/lofiversion/index.php/t20319.html import oracle.sql.*;import java.sql.*;import java.io.*;public class WriteBlob { public static void main(String[] args) { try { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@192.168.0.204:1521:main", "lct", "lct"); conn.setAutoCommit(false); BLOB blob = null; //清空 PreparedStatement pstmt = conn.prepareStatement( "update javatest set content=empty_blob() where name=?"); pstmt.setString(1, "liuchuntao"); pstmt.executeUpdate(); pstmt = conn.prepareStatement( "select content from javatest where name= ? for update"); pstmt.setString(1, "liuchuntao"); ResultSet rset = pstmt.executeQuery(); if (rset.next()) { blob = (BLOB) rset.getBlob(1); } String fileName = "e:\\pic\\1.jpg"; File f = new File(fileName); FileInputStream fin = new FileInputStream(f); System.out.println("file size = " + fin.available()); pstmt = conn.prepareStatement( "update javatest set content=? where name=?"); OutputStream out = blob.getBinaryOutputStream(); int count = -1, total = 0; byte[] data = new byte[ (int) fin.available()]; fin.read(data); out.write(data); fin.close(); out.close(); pstmt.setBlob(1, blob); pstmt.setString(2, "fankai"); pstmt.executeUpdate(); pstmt.close(); conn.commit(); rset.close(); conn.close(); } catch (SQLException e) { System.err.println(e.getMessage()); System.out.println(e.getErrorCode()); e.printStackTrace(); } catch (IOException e) { System.err.println(e.getMessage()); } }} java 这个情况怎样正确split map问题 List<Integer>转int[] 请问“仅当源级别为5.0时以参数化的类型才可用”是什么意思啊 询问调查:大家都用什么IDE开发JAVA? 关于keyListener的一个小代码,无法调对..... 一个简单的日期转换处理 画函数图像的计算器 我编的不是SQL eclipse 求救!提供有用源代码者加200分 请教计算器的编写
BLOB b = ( BLOB )dr.getItem( 0 );
OutputStream outs = b.getBinaryOutputStream();
ByteArrayInputStream bais = new ByteArrayInputStream( com.system.util.util.BASE64Decoder( dm.getParams().get( paramName ).getValue() ) );
byte[] buf = new byte[ b.getChunkSize() ];
int len;
while( ( len = bais.read( buf ) ) != -1 )
{
outs.write( buf , 0 , len );
}
outs.flush();
outs.close();
bais.close();
import java.sql.*;
import java.io.*;public class WriteBlob { public static void main(String[] args) { try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@192.168.0.204:1521:main", "lct", "lct");
conn.setAutoCommit(false);
BLOB blob = null;
//清空
PreparedStatement pstmt = conn.prepareStatement(
"update javatest set content=empty_blob() where name=?");
pstmt.setString(1, "liuchuntao");
pstmt.executeUpdate(); pstmt = conn.prepareStatement(
"select content from javatest where name= ? for update");
pstmt.setString(1, "liuchuntao");
ResultSet rset = pstmt.executeQuery();
if (rset.next()) {
blob = (BLOB) rset.getBlob(1); }
String fileName = "e:\\pic\\1.jpg";
File f = new File(fileName);
FileInputStream fin = new FileInputStream(f);
System.out.println("file size = " + fin.available()); pstmt = conn.prepareStatement(
"update javatest set content=? where name=?"); OutputStream out = blob.getBinaryOutputStream(); int count = -1, total = 0;
byte[] data = new byte[ (int) fin.available()];
fin.read(data);
out.write(data);
fin.close();
out.close(); pstmt.setBlob(1, blob);
pstmt.setString(2, "fankai"); pstmt.executeUpdate();
pstmt.close(); conn.commit();
rset.close();
conn.close();
}
catch (SQLException e) {
System.err.println(e.getMessage());
System.out.println(e.getErrorCode());
e.printStackTrace();
}
catch (IOException e) {
System.err.println(e.getMessage());
}
}}