Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Retrieve from mySQL table and show in JLabel

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to download image from mysql table ( tableUser(id, image) ) and to show in jlabel in java gui application.
mine code is :-


but it shows exception : inside retrieve : java.lang.NullPointerException

please tell me how to load image in jlabel
 
Master Rancher
Posts: 3921
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 it shows exception : inside retrieve : java.lang.NullPointerException


What line was that exception on?  What variable had the null value?

Call the printStackTrace method in the catch block to get more information.
 
rahul vishwakarma
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this exceptin shows after line byte [] buffer = new byte[b.available()];
 
Norm Radder
Master Rancher
Posts: 3921
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What was the variable with the null value?  What was the value in b when that statement was executed?
 
rahul vishwakarma
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
stacktrace is :
 
Norm Radder
Master Rancher
Posts: 3921
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What was the variable with the null value?  What was the value in b when that statement was executed?

What statement was on line 107?
 
rahul vishwakarma
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i tried to get value of b by "JOptionPane.showMessageDialog(null, "b is :  " + b.toString()); "
putting before " byte [] buffer = new byte[b.available()];"
and now this line is throwing exception. So i think b is null at that line. So please tell me how to  "retrieve image from mysql table and show in jlabel in java."
 
Saloon Keeper
Posts: 6585
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that b is indeed null (and you need to verify that, not just guess) - what do the javadocs say about when the return value of getBinaryStream can be null?

Also, post the SQL table declaration of the table in question.
 
rahul vishwakarma
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jova doc for getBinarySteam is :
public abstract InputStream  getBinarySteam(int i);
and  notihing more than that

and table is :-

tableUser
id primary key Not Null
image MEDIUMBLOB   NULL
 
Marshal
Posts: 25795
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I read all of the javadocs (not just the summary that you posted here) and they don't say that the method can or can't return null.

However your database description says the blob can be null, so presumably there could be rows which don't contain an image. Probably for those rows you get null, rather than an empty InputStream. So you ought to change things so either (a) the database doesn't allow null in that column, or (b) your Java code checks for null and acts accordingly.
 
Dinner will be steamed monkey heads with a side of tiny ads.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic