zoukankan      html  css  js  c++  java
  • IBatis存取图片在Oracle Blob大字段中Asp.Net

    cs 代码

    /// <summary>
        /// 添加一个图片
        /// </summary>
        public void AddImageToOracle()
        {
            AdvertisementManager am = new AdvertisementManager();
            Advertisement a = new Advertisement();
            string file_name = "C:\\szs.jpg";
            FileStream fs = new FileStream(file_name, FileMode.OpenOrCreate, FileAccess.Read);
            byte[] MyData = new byte[fs.Length];
            fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length));
            fs.Close();
            a.AdImage = MyData;
            am.AddAdvertisement(a);
    
        }
        /// <summary>
        /// 读取一个图片
        /// </summary>
        public void ShowImageFromOracle()
        {
            AdvertisementManager am = new AdvertisementManager();
            Advertisement a = new Advertisement();
            a = am.GetAdvertisementById(41);
            byte[] bytes = a.AdImage;
            Response.AppendHeader("Content-Length", bytes.Length.ToString());
            Response.BinaryWrite(bytes);
        }
    配置
    普通的配置就可以
    <insert id="Advertisement.Insert" parameterClass="Advertisement">
                INSERT INTO AD_ADVERTISEMENT (ID,AD_NAME,AD_TYPE,AD_STATE,AD_WIDTH,AD_HEIGHT,AD_IMAGE,AD_CODE)
                 VALUES (#Id#,#AdName#,#AdType#,#AdState#,#AdWidth#,#AdHeight#,#AdImage#,#AdCode#)
                <selectKey resultClass="int" type="pre" property="Id" >
                    SELECT seq_AD_ADVERTISEMENT.NEXTVAL AS VALUE FROM DUAL
                </selectKey> 
            </insert>
    Po 对于大字段的对应属性,用byte[]就可以了
    /// <summary>
            /// 图片
            /// </summary>
            private byte[] adimage;
            /// <summary>
            /// 图片
            /// </summary>
            public byte[] AdImage
            {
                get{return adimage;}
                set{adimage = value;}
            }
    冯瑞涛
  • 相关阅读:
    pod
    jquery日历插件
    web前端常用api
    VUE.JS——脚手架安装
    github入门到上传本地项目
    appach修改默认端口之后数据库的访问
    在脚本中刷新impala元信息
    在脚本中刷新impala元信息
    不同hadoop集群之间迁移hive数据
    不同hadoop集群之间迁移hive数据
  • 原文地址:https://www.cnblogs.com/finehappy/p/1601851.html
Copyright © 2011-2022 走看看