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

    }

  • 相关阅读:
    关于 Web 性能优化
    重命名某一路径下文件
    使用相对坐标定位元素
    使用appium做自动化时如何切换activity
    newman安装时遇到问题的解决
    pytesser的使用
    用户名密码的参数化(读取文件)
    百度登录
    Python 3中套接字编程中遇到TypeError: 'str' does not support the buffer interface的解决办法
    百度搜索设置下拉框的操作
  • 原文地址:https://www.cnblogs.com/haofaner/p/5652755.html
Copyright © 2011-2022 走看看