int i = 0;
while ((i = input.read(buffer)) != -1) {
output.write(buffer, 0, i);
}
}
System.out.println("=====================get file end========================");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 修改blob内容
*/
public static void updateblob(String id) {
Connection conn = JdbcUtil.getConnection();
Statement stem = null;
ResultSet rs = null;
try {
conn.setAutoCommit(false);
stem = conn.createStatement();
System.out.println("=====================update file begin========================");
rs = stem.executeQuery("select file_blob from johnny_file where id='"
+ id + "' for update");
if (rs.next()) {
BLOB blob = (BLOB) rs.getBlob("file_blob");
OutputStream outStream = blob.getBinaryOutputStream();
InputStream fin = new FileInputStream("D://ok.zip");
byte[] b = new byte[blob.getBufferSize()];
int len = 0;
while ((len = fin.read(b)) != -1) {
outStream.write(b, 0, len);
}
fin.close();
outStream.flush();
outStream.close();
conn.commit();
conn.close();
}
System.out.println("=====================update file end========================");
} catch (Exception ex) {
try {
conn.rollback();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(ex.getMessage());
}
}
}
2:以下这个是我自己的jdbc工具类
import java.sql.*;
public class JdbcUtil {
/**
* driverName
* */
static{
String driverName="oracle.jdbc.driver.OracleDriver";
try{
Class.forName(driverName);
}catch(Exception e){
e.printStackTrace();
}
}
/**
* getConnection
* */
public static Connection getConnection(){
String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
String userName="XXXXX";
String pwd="XXXXXX";
Connection con = null;
try{
con = DriverManager.getConnection(url,userName,pwd);
}catch(Exception ee){
ee.printStackTrace();
}
return con;
}
/**
* close
* */
public static void close(ResultSet rs,Statement stmt,Connection con){
try{
if(rs!=null){rs.close();}
}catch(Exception ee){
ee.printStackTrace();
}
try{
if(stmt!=null){stmt.close();}
}catch(Exception ee){
ee.printStackTrace();
}
try{
if(con!=null){con.close();}
}catch(Exception ee){
ee.printStackTrace();
}
}
}
作者:“Johnny的零度”