title: Problem on inserting & retrieve image data in sqlite database using android
body: <p>I am new to android development. Currently i am facing a problem while <code>inserting/retrieving</code> image to <code>SQLite database</code> using android.</p>
  
  <pre><code>//code for inserting image
  InputStream in = OpenHttpConnection(imgurl);
  
  byte[] bb = new byte[in.available()];
  
  in.read(bb);//here the length of bb is 2040
  
  //update query
  
  myDataBase.execSQL("Update Product SET Image='"+bb+"' Where CatPID='"+pcpid+"'");
  
  //function OpenHttpConnection
  private InputStream OpenHttpConnection(String urlString)  throws IOException
  {
      InputStream in = null;
      int response = -1;
  
      URL url = new URL(urlString); 
      URLConnection conn = url.openConnection();
  
      if (!(conn instanceof HttpURLConnection))                     
          throw new IOException("Not an HTTP connection");
  
      try{
          HttpURLConnection httpConn = (HttpURLConnection) conn;
          httpConn.setAllowUserInteraction(false);
          httpConn.setInstanceFollowRedirects(true);
          httpConn.setRequestMethod("GET");
          httpConn.connect(); 
  
          response = httpConn.getResponseCode();                 
          if (response == HttpURLConnection.HTTP_OK) {
              in = httpConn.getInputStream();                                 
          }                     
      }
      catch (Exception ex)
      {
          throw new IOException("Error connecting");            
      }
      return in;     
  }
  
  //code for retrieve image from database
  
  byte[] bb = cursor.getBlob(cursor.getColumnIndex("Image"));//here length is only 12
  
  ByteArrayInputStream imageStream = new ByteArrayInputStream(bb);
  
  Bitmap theImage = BitmapFactory.decodeStream(imageStream);
  
  img.setImageBitmap(theImage);
  </code></pre>
  
  <p>But no image is shown.Log shows "Factory returned null"</p>
  
  <p>Can anyone help me to find out where I am wrong and provide me code snippet of a working solution?</p>
  
  <p>Thanks in advance</p>