Java mysql blob 資料讀寫操作
阿新 • • 發佈:2021-07-07
package com.lw.database; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; /*** CREATE: CREATE TABLE IDCard ( id char(18),pic BLOB); * @author fhadmin * from www.fhadmin.cn */ public class LOBTest { protected static final String DEFAULT_URL = "jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8"; protected static final String DRIVER_NAME = "com.mysql.jdbc.Driver";private Connection connection = null; public LOBTest() throws ClassNotFoundException, SQLException { Class.forName(DRIVER_NAME); connection = DriverManager.getConnection(DEFAULT_URL, "user", "password"); } public void insert(String id,String path) throws SQLException, IOException { PreparedStatement preparedStatement= connection.prepareStatement("INSERT INTO IDCard VALUES (?,?)"); preparedStatement.setString(1, id); FileInputStream fileInputStream = new FileInputStream(path); preparedStatement.setBlob(2, fileInputStream,fileInputStream.available()); preparedStatement.execute(); } public void get(String id) throws SQLException, IOException { PreparedStatement preparedStatement = connection.prepareStatement("SELECT pic FROM IDCard WHERE id = ?"); preparedStatement.setString(1, id); ResultSet results = preparedStatement.executeQuery(); while(results.next()) { FileOutputStream outputStream = new FileOutputStream("/Users/liuwei/temp.png"); InputStream inputStream = results.getBinaryStream(1); int num = -1; while((num=inputStream.read())!=-1) { outputStream.write(num); } outputStream.flush(); inputStream.close(); outputStream.close(); } } public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException { LOBTest test = new LOBTest(); test.insert("78907656784323", "/Users/liuwei/Documents/bt_next_nor.png"); test.get("78907656784323"); } }
注意:
MySQL的四種BLOB型別
型別大小(單位:位元組)
TinyBlob最大255B
Blob最大65K
MediumBlob最大16M
LongBlob最大4G
插入影象的時候,注意下影象大小,影象超過該型別所能容納的最大位元組的時候,會報錯
工作流模組--------------------------------------------------------------------------www.fhadmin.cn 1.模型管理 :web線上流程設計器、預覽流程xml、匯出xml、部署流程 2.流程管理 :匯入匯出流程資原始檔、檢視流程圖、根據流程例項反射出流程模型、啟用掛起 3.執行中流程:檢視流程資訊、當前任務節點、當前流程圖、作廢暫停流程、指派待辦人 4.歷史的流程:檢視流程資訊、流程用時、流程狀態、檢視任務發起人資訊 5.待辦任務 :檢視本人個人任務以及本角色下的任務、辦理、駁回、作廢、指派一下代理人 6.已辦任務 :檢視自己辦理過的任務以及流程資訊、流程圖、流程狀態(作廢 駁回 正常完成)注:當辦理完當前任務時,下一任務待辦人會即時通訊收到新任務訊息提醒,當作廢和完結任務時,
任務發起人會收到站內信訊息通知