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

    }

  • 相关阅读:
    Windows7在自由的虚拟机(微软官方虚拟机)
    POJ1135_Domino Effect(最短)
    项目优化经验分享(七)敏捷开发
    POJ 3299 Humidex(简单的问题)
    NEFUOJ 500 二分法+最大流量
    json 解析解乱码
    【设计模式】Abstract Factory模式
    汇编语言的应用
    Duanxx的STM32学习:NVIC操作
    PHP移动互联网的发展票据(6)——MySQL召回数据库基础架构[1]
  • 原文地址:https://www.cnblogs.com/haofaner/p/5652755.html
Copyright © 2011-2022 走看看