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\\User\\Desktop\\附件章模板.img");
int len =(int)file.length();
InputStream inStream = new FileInputStream(file);
Connection conn =
DriverManager.getConnection(
"jdbc:oracle:thin:@10.20.*:1521:orcl",
"sunyard", "sunyard");
/*将附件章插入数据库表*/
PreparedStatement ps = conn.prepareStatement("insert into sm_page_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字段插入图片的方法
于 2017-06-12 21:23:04 首次发布