oracle 建表blob字段,向oracle表的BLOB字段插入图片的方法

package jdbc.day01; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; /**  *   *   * 将附件章插入数据库表*/ public class BolbTest { public static void main(String[] args) throws FileNotFoundException, SQLException { File file = new File("C:\\Users\\Zugantan\\Desktop\\附件章模板.img"); int len =(int)file.length(); InputStream inStream = new FileInputStream(file); Connection conn =  DriverManager.getConnection( "jdbc:oracle:thin:@10.20.188.82:1521:orcl", "sunyard", "sunyard"); /*将附件章插入数据库表*/ PreparedStatement ps = conn.prepareStatement("insert into sm_page_seal_tb(sealimage) values (?)" ); ps.setBinaryStream(1, inStream,len); boolean flag = ps.execute(); if(flag==true){  //成功 System.out.println("BLOB............."); }else{ System.out.println("fail...."); } conn.commit(); ps.close(); conn.close(); } }

你可能感兴趣的:(oracle,建表blob字段)