jdbc 插入、读取oracle blob字段

Java代码 JDBC 操作 oracle blob _oracle JDBC 操作 oracle blob _oracle_02
  1.  
  2. package com.ssgm.jyu.jdbc;
  3. import java.io.*;
  4. import java.sql.*;
  5.  
  6. import oracle.sql.*;
  7. import oracle.jdbc.*;
  8.  
  9. public class JdbcBlob {
  10. public static void main(String[] args){
  11. Connection conn = null;
  12. Statement stmt = null;
  13. try{
  14. Class.forName("oracle.jdbc.driver.OracleDriver");
  15. }
  16. catch(ClassNotFoundException e){
  17. e.printStackTrace();
  18. }
  19.  
  20. try{
  21. conn = DriverManager.getConnection("jdbc:oracle:thin:@Host:1521:SID","username","passwd");
  22. stmt = conn.createStatement();
  23. conn.setAutoCommit(false);
  24. String sourceDir = "C:\\temp\\";
  25. String targetDir = "C:\\temp\\retrieved\\";
  26. String fileName = "cbr_order_version.dmp";
  27. System.out.println("Writing BLOB to blob_content...");
  28. writeBLOB(stmt,sourceDir+fileName);
  29. System.out.println("Reading BLOB from blob_content...");
  30. readBLOB(stmt,fileName,sourceDir,targetDir);
  31. }
  32. catch(SQLException e){
  33. e.printStackTrace();
  34. }
  35. finally{
  36. try{
  37. stmt.close();
  38. conn.close();
  39. }
  40. catch(SQLException e){
  41. e.printStackTrace();
  42. }
  43. }
  44. }