您是第欢迎光临我的主页位访客
浩凡儿
天行健,君子以自强不息;地势坤,君子以厚德载物!
@Test
     public void run() throws ClassNotFoundException, SQLException,
                FileNotFoundException {
 
            try {
                Connection conn = jdbcUtils. getConnection();
                PreparedStatement pst = conn
                           .prepareStatement( "insert into myblob values(null,?)");
                File file = new File( "E:\\Java\\学习\\day17-jdbc\\视频\\1.课程介绍.avi" );
                FileInputStream fs = new FileInputStream(file);
                pst.setBinaryStream(1, fs, ( int) file.length());
                 int row = pst.executeUpdate();
                 if (row != 0) {
                     System. out.println( "插入成功");
                }
           } catch (Exception e) {
                e.printStackTrace();
           }
 
     }
 
 

@Test
public void save() throws ClassNotFoundException, SQLException,
FileNotFoundException {
try {
Connection conn = jdbcUtils.getConnection();
PreparedStatement pst = conn
.prepareStatement("insert into mytext values(null,?)");
File file = new File("E:\\Java\\Workspaces\\DAO\\a.txt");
FileReader fr = new FileReader(file);
pst.setCharacterStream(1, fr, (int) file.length());
int row = pst.executeUpdate();
if (row != 0) {
System.out.println("插入成功");
}
} catch (Exception e) {
e.printStackTrace();
}

}

posted on 2016-07-08 11:17  浩凡儿  阅读(933)  评论(0编辑  收藏  举报