• blob


    import java.io.File;
    import java.io.FileInputStream;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    
    public class Main {
      static String url = "jdbc:oracle:thin:@localhost:1521:javaDemo";
      static String username = "username";
      static String password = "welcome";
    
      public static void main(String[] args) throws Exception {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection conn = DriverManager.getConnection(url, username, password);
        conn.setAutoCommit(false);
    
        String sql = "INSERT INTO pictures (name, description, image) VALUES (?, ?, ?)";
        PreparedStatement stmt = conn.prepareStatement(sql);
        stmt.setString(1, "java.gif");
        stmt.setString(2, "Java Official Logo");
    
        File image = new File("D:\a.gif");
        FileInputStream   fis = new FileInputStream(image);
        stmt.setBinaryStream(3, fis, (int) image.length());
        stmt.execute();
    
        conn.commit();
        fis.close();
        conn.close();
      }
    } 
     
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    
    public class Main {
      static String url = "jdbc:oracle:thin:@localhost:1521:javaDemo";
      static String username = "username";
      static String password = "welcome";
      public static void main(String[] args) throws Exception {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection conn = DriverManager.getConnection(url, username, password);
    
        String sql = "SELECT name, description, image FROM pictures ";
        PreparedStatement stmt = conn.prepareStatement(sql);
        ResultSet resultSet = stmt.executeQuery();
        while (resultSet.next()) {
          String name = resultSet.getString(1);
          String description = resultSet.getString(2);
          File image = new File("D:\java.gif");
          FileOutputStream fos = new FileOutputStream(image);
    
          byte[] buffer = new byte[1];
          InputStream is = resultSet.getBinaryStream(3);
          while (is.read(buffer) > 0) {
            fos.write(buffer);
          }
          fos.close();
        }
        conn.close();
      }
    }
  • 相关阅读:
    python-excel操作
    python-处理文件
    python-pandas应用总结
    python比较数组
    vue学习一(指令1.v-text,v-html,插值表达式{{msg}})
    博客园背景图页面定制css
    SpringBoot的yml文件报org.yaml.snakeyaml.scanner.ScannerException: mapping values are not allowed here in 'reader', line 11, column 16:
    python初学习一
    C#多线程
    API与WebApi
  • 原文地址:https://www.cnblogs.com/yasepix/p/6423080.html
Copyright © 2020-2023  润新知