解决方法:

1:在后台以InputStream的方式将图片从数据库中读出:

public static InputStream getPicInputStream(){
String id = "f304733361e243779b2340afe20e62bf"; Connection conn = JdbcUtil.getConnection(); PreparedStatement ps = null; ResultSet rs = null; InputStream is = null; String sql = "select zp from pic_test where id= ?"; try { ps = conn.prepareStatement(sql); ps.setString(1, id); rs = ps.executeQuery(); if(rs.next()){
is = rs.getBlob("zp").getBinaryStream();
} } catch (SQLException ex) {
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
}finally{
try {
if(null!=ps){
ps.close();
}
} catch (SQLException ex) {
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
}
try {
if(null!=rs){
rs.close();
}
} catch (SQLException ex) {
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
}
JdbcUtil.release(conn);
} return is;
}

2:在Servlet中直接生成图片:

response.setContentType("image/jpeg");

        InputStream is = Test.getPicInputStream();

        if(null!=is){

            OutputStream os = response.getOutputStream();

            int len;

            byte buf[] = new byte[1024];

            while((len=is.read(buf))!=-1){
os.write(buf, 0, len);
} is.close();
os.close();
}

3:Android客户端的处理

public class MainActivity extends Activity {

    ImageView imgView;

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); imgView = (ImageView)findViewById(R.id.imgView); new ImgViewAsyncTask().execute("");
} class ImgViewAsyncTask extends AsyncTask<String,String,String>{
Bitmap bitmap = null; @Override
protected void onPreExecute() { } @Override
protected String doInBackground(String... strings) {
InputStream is = null;
String result = ""; try {
URL picURL = new URL("http://192.168.0.165:8084/wisdompm/PicServlet");
HttpURLConnection conn = (HttpURLConnection)picURL.openConnection();
conn.setConnectTimeout(10000);
conn.connect(); is = conn.getInputStream();
if(null!=is){
bitmap = BitmapFactory.decodeStream(is);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
if(null!=is){
is.close();
}
} catch (IOException e) {
e.printStackTrace();
}
} return result;
} @Override
protected void onPostExecute(String s) {
if(null!=bitmap && null!=imgView){
imgView.setImageBitmap(bitmap);
}
}
}
}

测试结果:

图片以BLOB存储在后台数据库中,Android客户端要进行读取显示的更多相关文章

  1. SharePoint 2013 使用 RBS 功能将二进制大型对象 BLOB 存储在内容数据库外部。

    为每个内容数据库设置 BLOB 存储   启用并配置 FILESTREAM 之后,请按照以下过程在文件系统中设置 BLOB 存储.必须为要对其使用 RBS 的每个内容数据库设置 BLOB 存储. 设置 ...

  2. Python爬取招聘信息,并且存储到MySQL数据库中

    前面一篇文章主要讲述,如何通过Python爬取招聘信息,且爬取的日期为前一天的,同时将爬取的内容保存到数据库中:这篇文章主要讲述如何将python文件压缩成exe可执行文件,供后面的操作. 这系列文章 ...

  3. 将 flask 中的 session 存储到 SQLite 数据库中

    将 flask 中的 session 存储到 SQLite 数据库中 使用 flask 构建服务器后端时,常需要在浏览器端存储 cookie 用于识别不同用户,根据不同的 cookie 判断出当前请求 ...

  4. 利用POI工具读取word文档并将数据存储到sqlserver数据库中

    今天实现了利用POI工具读取word文档,并将数据存储到sql数据库中,代码如下: package word; import java.io.File; import java.io.FileInpu ...

  5. EasyUI动态显示后台数据库中的数据

    最近在完成一个项目,采用SSM框架搭建完成,前端使用EasyUI搭建页面: 其中涉及到一个查询显示功能:查询数据库中的数据,动态显示在页面之中,刚开始这部分十分有疑问,所以虚心向同学学习,现总结至博客 ...

  6. 通过JSP网页连接MySQL数据库,从MySQL数据库中读出一张表并显示在JSP网页中

    1.安装所需软件 ①安装java和tomcat,建立JSP网页最基础的软件②安装MySQL数据库(下载地址:https://www.mysql.com/)③安装Navicat Premium来查看数据 ...

  7. scrapy 自定义图片路径保存,并存到数据库中

    scrapy中有个自带的pipeline工具,ImagesPipeline,可以专门用来储存图片到本地. 但默认储存地址无法配置,所以我们需要写一个自己的pipeline用于储存图片. 先分析一下我们 ...

  8. .net的session详解 存储模式 存到数据库中 使用范围与大小限制 生命周期

    Session又称为会话状态,是Web系统中最常用的状态,用于维护和当前浏览器实例相关的一些信息.举个例子来说,我们可以把已登录用户的用户名放在Session中,这样就能通过判断Session中的某个 ...

  9. Java爬网页数据,并存储到本地数据库中

    由于开发一个人工智能项目,需要强大的后台数据库加持,所以,没有办法,又是需要医疗数据,只能自己爬某医疗网站数据,进行分析,但是由于不同网站的结构不一样,所以这个程序只能爬该网站的,第一次爬网页数据,自 ...

随机推荐

  1. Pick two points at random from the interior of a unit square, what is the expected distance between them?

    My solution is as folllowing. This integration is hard to solve. I googled it, and found the result ...

  2. Unity3D中C#编写脚本

    1.继承MonoBehaviour类:任何一个游戏脚本都需要去继承MonoBehaviour这个类,只是在创建javascript脚本的时候,系统会将其类名与继承关系隐藏起来. 2.声明变量:使用Ja ...

  3. SSH转发机制

    第一部分 概述 当你在咖啡馆享受免费 WiFi 的时候,有没有想到可能有人正在窃取你的密码及隐私信息?当你发现实验室的防火墙阻止了你的网络应用端口,是不是有苦难言?来看看 SSH 的端口转发功能能给我 ...

  4. 管理Undo数据

    SQL> select sum(bytes),status from dba_undo_extents group by status; SUM(BYTES) STATUS ---------- ...

  5. Asp.Net 构架(Http Handler 介绍) - Part.2

    原文地址:http://www.cnblogs.com/JimmyZhang/archive/2007/09/15/894124.html 引言 在 Part.1 Http请求处理流程 一文中,我们了 ...

  6. 在CentOS中编译安装VIM 7.3

    默认安装的 Vim 不带有多字符支持,所以不支持中文.无论是将 CentOS 本来的语系改为中文还是将 Vim 的语系设置改为中文,都不能正常显示中文.为了在 Vim 中能够正常处理中文,我们需要在编 ...

  7. Javascript:字符串分割split()妙用

    概述: split() 方法将字符串分割为字符串数组,并返回此数组 语法格式: stringObject.split(separator,limit) 参数说明: 注意:如果把空字符串 (" ...

  8. 压位加速-poj-2443-Set Operation

    题目链接: http://poj.org/problem?id=2443 题目意思: 有n个集合(n<=1000),每个集合有m个数ai(m<=10000,1=<ai<=100 ...

  9. Dynamics CRM 开发模板使用手册(插件开发)

    CRM开发手册 本手册介绍在Visual Studio 2015 + Dynamics CRM Developer Extensions模板开发环境下,插件和JS脚本的开发.部署与调试过程. 手册中提 ...

  10. compareTo简介

    compareTo()方法是用来比较字符串大小,该方法用来判断一个字符串是大于,等于还是小于另一个字符串.判断字符串大小的依据是根据他们在字典中的顺序决定的 语法 Str1.compareTo(Str ...