oracle读写图片(C#,Java)
来源:互联网 发布:加工中心半圆编程 编辑:程序博客网 时间:2024/05/16 08:03
//C#篇 //写入 string connStr = "Data Source=123;user id=123;password=123"; OracleConnection conn = new OracleConnection(connStr); try { conn.Open(); string fileName = @"D:\121.jpg"; FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Read); byte[] image = new byte[fs.Length]; fs.Read(image, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); OracleCommand cmd = new OracleCommand("INSERT INTO table (pic_name,pic_content) VALUES ('123',empty_blob()) ", conn); cmd.ExecuteNonQuery(); OracleDataAdapter da = new OracleDataAdapter("select * from r_pic_glss where glass_id='AKA0703TUB' and pic_url='123' for update ", conn); OracleCommandBuilder ocb = new OracleCommandBuilder(da); DataSet ds = new DataSet(); da.Fill(ds); da.MissingSchemaAction = MissingSchemaAction.AddWithKey; ds.Tables[0].Rows[0]["pic_content"] = image; da.Update(ds.Tables[0]); } catch (Exception ex) { // } finally { conn.Close(); } //读取图片并放到listview imageList1 = loadPicbyName(picList); imageList1.ImageSize = new Size(128, 128); listView1.LargeImageList = imageList1; public ImageList loadPicbyName(List<string> picNameList) { ImageList il = new ImageList(); foreach (string pic in picNameList) { Image image = queryImageDataByName(pic); if (image != null) { il.Images.Add(image); } } return il; } public Image queryImageDataByName(string pic_name) { string sql = string.Format(" select t.* from table t where t.pic_name = '{0}' ", pic_name); SqlBean sqlBean = new SqlBean(); DataTable dt = sqlBean.doQuery(sql); if (dt != null && dt.Rows.Count > 0) { System.Byte[] pic_content = (byte[])dt.Rows[0]["pic_content"]; MemoryStream buf = new MemoryStream(pic_content); Image image = Image.FromStream(buf, true); return image; } else { return null; } }
//java
private FTPClient ftp;public byte[] downloadFileIntoByte(String remoteFilePath)throws Exception {byte[] byteRtn = new byte[0];try {long time1 = System.currentTimeMillis();if (!ftp.isConnected()) {connect();}ftp.enterLocalPassiveMode();ftp.setFileType(FTP.BINARY_FILE_TYPE);InputStream in = ftp.retrieveFileStream(remoteFilePath);int c;byte[] bytes = new byte[1024];while ((c = in.read(bytes)) != -1) {int preByteRtnLen = byteRtn.length;byte[] byteRtnTemp = byteRtn;byteRtn = new byte[preByteRtnLen + c];System.arraycopy(byteRtnTemp, 0, byteRtn, 0, byteRtnTemp.length);if (c < 1024) {System.arraycopy(bytes, 0, byteRtn, preByteRtnLen, c);} else {System.arraycopy(bytes, 0, byteRtn, preByteRtnLen,1024);}}in.close();ftp.completePendingCommand();} catch (Exception e) {_log.error("downloadFileIntoByte [" + remoteFilePath + "] Fail", e);throw e;}return byteRtn;}private void insertIamgeIntoDB(RPicGlss rpg) throws Exception {StringBuffer sql = new StringBuffer();sql.append(" INSERT INTO table ");sql.append(" (pic_name, pic_content) ");sql.append(" VALUES ");sql.append(" (?, empty_blob) ");SqlBean sqlBean = new SqlBean(sql.toString);sqlBean.addParameter("123");int updateCount = sqlBean.executeUpdate();if (updateCount == 1) {sql.setLength(0);sqlBean = null;StringBuffer sql = new StringBuffer();sql.append("SELECT pic_content ");sql.append("FROM table ");sql.append("WHERE pic_name = ? ");sql.append(" FOR UPDATE ");sqlBean = new SqlBean(sql.toString());sqlBean.addParameter("123");List<Map> rtnLm = sqlBean.executeQuery();Blob blob = (Blob) rtnLm.get(0).get("pic_content");OutputStream os = blob.setBinaryStream(0);os.write(downloadFileIntoByte("D:\121.jpg"));os.flush();os.close();} else {throw new Exception("[Insert Record Fail] " + rpg.getPicUrl());}}
- oracle读写图片(C#,Java)
- Oracle读写数据库图片
- java图片读写修改
- java图片读写程序
- java图片读写
- java 图片读写
- Java bitmap图片读写
- oracle数据库的图片读写
- 图片在Oracle中读写
- Oracle中图片的读写
- java常用图片读写程序
- java读写Oracle clob数据
- java oracle blob 读写操作
- java读写Oracle Blob字段
- C语言读写BMP格式图片
- 如何读写Oracle数据库Blog字段(Java)
- JAVA读写Oracle中blob字段
- JAVA处理Oracle数据库CLOB读写操作
- 计划一个公司聚会
- linux c 改变控制台输出字体颜色
- 子衿的事(44)
- Tortoise SVN使用方法,简易图解
- 路(续)
- oracle读写图片(C#,Java)
- 当乔布斯遇见稻盛和夫
- 机房收费系统验收报告
- What is a software architecture?
- 如何实现来电拦截及拦截后的提示音
- android 对sqlite数据库的增删改查
- 程序员下班去超市购物与收银员的一段搞笑对白 续集
- ati2dvag错误—笔记本启动滚动条结束后进入系统蓝屏
- 三国杀Excel版–让你见证Excel的神奇