Java bean gives null pointerexception

   I know this is really very very funny.At times my java bean application works and at times it give an exception of null pointer.
I think my problem is that maybe i am not using the get  properly,

I mean, when i use set i use:

<jsp:useBean id="vol" class="com.dhal.volun" scope="session"/>
<jsp:setProperty name="vol" property="*"/>

But i use the getters such as:

Do i need to write something maybe to use it, for example,


coz, when i look at work folder for the jas_jsp files it seems as if vol is null.

But if write
username gets printed so i am surprise which is null.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

the is nothing wrong of the code that u have posted. the problem is in somewhere else, post the full stack trace of you exception.
Jasbir21Author Commented:

When  i looked at the line 250,it is about this line

The java code for query that i use is....

   connection = DriverManager.getConnection(connectionURL, "", "");
   String myquery="select * from account where username='Jasbir22'";

   String query="select * from volunteer where username='Jasbir22'";

    .......//its is alot here


   catch(SQLException ex ) {  ex.printStackTrace() ; }

   catch( ClassNotFoundException ex ){  ex.printStackTrace() ; }


rs.getString(2) is giving you null.

make sure password is the column number 2 and it is not null for user Jasbir22.
BTW, I'd suggest you to use column name instead of possition, since position might change if you add new columns to database.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Jasbir21Author Commented:
   I don't understand something, does it mean that a column value cannot be null because if its it would give a null pointer,
sometimes, a user would need not enter a column, soit is null

Jasbir21Author Commented:
when i type describle table,

i get

So, i guess it is at column 2 ????

How do i do it the column name way

>So, i guess it is at column 2 ????
columns are counted from ResultSet, not DB schema, but in your it's the same, because you retrive all columns.

>How do i do it the column name way
just use overloading methods in ResultSet:
    String s=rs.getString("password");

Jasbir21Author Commented:
When you say column are counted from Resultset,

how are they are counted...

>> When you say column are counted from Resultset.
that's the order in your select statment. it's same if you use select *, but if you use select password, username from..., then the order is password, username.

>> does it mean that a column value cannot be null
NO, the problem is that you are doing a trim(), so if the rs.getString() returns null, you are doing s = null.trim(), of course, you get NPE.
for those columns that could be null in database, you should always use
String s = rs.getString("columnname");
if( s != null ) s=s.trim();
Jasbir21Author Commented:
......I have been spending days to find out what my problem, and you guys in experts - exchange solved in seconds.Thank you so much....

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.