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.已办任务   :查看自己办理过的任务以及流程信息、流程图、流程状态(作废 驳回 正常完成)

注:当办理完当前任务时,下一任务待办人会即时通讯收到新任务消息提醒,当作废和完结任务时,
       任务发起人会收到站内信消息通知