zoukankan      html  css  js  c++  java
  • 向mysql数据库中插入大二进制文件和大文本

    @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();
    }

    }

  • 相关阅读:
    找工作就上智联,效果真快,然而让我去的公司都是泡我呢
    只能面深度学习岗和算法岗,其他都不会
    2维矩阵前缀和技巧题目
    计算机基础背诵
    集合函数AVG,SUM,MAX,MIN
    集合函数COUNT
    修改删除数据记录
    多表查询
    查询数据表中的记录
    SQL基本语句(3) LOAD DATA INFILE
  • 原文地址:https://www.cnblogs.com/haofaner/p/5652755.html
Copyright © 2011-2022 走看看