jdbc 插入、读取oracle blob字段
- package com.ssgm.jyu.jdbc;
- import java.io.*;
- import java.sql.*;
- import oracle.sql.*;
- import oracle.jdbc.*;
- public class JdbcBlob {
- public static void main(String[] args){
- Connection conn = null;
- Statement stmt = null;
- try{
- Class.forName("oracle.jdbc.driver.OracleDriver");
- }
- catch(ClassNotFoundException e){
- e.printStackTrace();
- }
- try{
- conn = DriverManager.getConnection("jdbc:oracle:thin:@Host:1521:SID","username","passwd");
- stmt = conn.createStatement();
- conn.setAutoCommit(false);
- String sourceDir = "C:\\temp\\";
- String targetDir = "C:\\temp\\retrieved\\";
- String fileName = "cbr_order_version.dmp";
- System.out.println("Writing BLOB to blob_content...");
- writeBLOB(stmt,sourceDir+fileName);
- System.out.println("Reading BLOB from blob_content...");
- readBLOB(stmt,fileName,sourceDir,targetDir);
- }
- catch(SQLException e){
- e.printStackTrace();
- }
- finally{
- try{
- stmt.close();
- conn.close();
- }
- catch(SQLException e){
- e.printStackTrace();
- }
- }
- }