網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
- 寫 區(qū)別
用流替換占位符 - 寫 getBinaryStream(列名) 返回InputStream
- 代碼
public static void main(String[] args) {
String sql_1 ="update test set img = ? where id = ?";
String sql_2 ="select img from test where id = ?";
InputStream binaryStream = null;
try (FileOutputStream fos = new FileOutputStream("animate1.jpg");
FileInputStream fis = new FileInputStream("C:\\Users\\123\\Desktop\\可愛(ài).jpg");
Connection connection = JDBCUtil.getConnection();
PreparedStatement ps = Objects.requireNonNull(connection).prepareStatement(sql_2);
) {
// 讀入圖片
// ps.setObject(1,fis);
// ps.setObject(2,1);
// ps.execute();
// 讀出圖片
ps.setObject(1,1);
ResultSet rs = ps.executeQuery();
while(rs.next()){
binaryStream = rs.getBinaryStream("img");
int len;
byte[] buffer = new byte[1024];
while ((len = binaryStream.read(buffer))!=-1) {
fos.write(buffer, 0, len);
}
}
}catch (Exception e){
e.printStackTrace();
}finally {
try {
if(binaryStream!=null)
binaryStream.close();
}catch (Exception e){
e.printStackTrace();
}
}
}
補(bǔ)充
- 默認(rèn)BLOB最大65k 用 MEDIUMBLOB類型最大16M
- max_allowed_packet = 16M 修改系統(tǒng)變量,不然最大就是最大只能1M
- new FileOutputStream(“animate1.jpg”)構(gòu)造方法封裝了創(chuàng)建File的匿名類
原文鏈接:https://blog.csdn.net/qq_51682771/article/details/125859730
相關(guān)推薦
- 2022-07-23 SpringBoot分頁(yè)查詢
- 2022-02-14 centos7系統(tǒng)部署k8s集群詳細(xì)介紹_Linux
- 2022-08-27 .net+FusionChart實(shí)現(xiàn)動(dòng)態(tài)顯示的柱狀圖和餅狀圖_實(shí)用技巧
- 2022-12-10 C++?Boost?Spirit精通教程_C 語(yǔ)言
- 2022-05-22 C#裝箱和拆箱的原理介紹_C#教程
- 2022-05-05 R語(yǔ)言因子類型的實(shí)現(xiàn)_R語(yǔ)言
- 2023-11-19 樹(shù)莓派/arm設(shè)備上安裝火狐Firefox瀏覽器
- 2022-04-03 Python?八個(gè)數(shù)據(jù)清洗實(shí)例代碼詳解_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支