Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / September 2003

Tip: Looking for answers? Try searching our database.

Why it doesn't work - jsp session

Thread view: 
KS - 09 Sep 2003 23:46 GMT
Hello,

The code bellow works fine on Windows tomcat but doesn't on Linux.
I recompiled it. Could you give me any idea why it is so?
It thrown null pointer exception on if line.
I know that before calling dbconn.getConnection() i should check wheather is
dbconn != null.
If it is because of Tomcats settings where and what should i change to make
it work?

thx,
Kanar

DBConnection dbconn=(DBConnection)session.getAttribute("dbconn");
if(dbconn.getConnection() != null){//session didn't expired
....
}
Palle Mogensen - 10 Sep 2003 22:53 GMT
Hi KS.

dbconn is null. Therefore dbconn.getConnection() will give
NullPointerException.

The correction syntax is:

DBConnection dbconn=(DBConnection)session.getAttribute("dbconn");
if(dbconn!=null && dbconn.getConnection() != null){//session didn't expired
....
}

regards
Palle

> Hello,
>
[quoted text clipped - 13 lines]
> ....
> }
Palle Mogensen - 10 Sep 2003 23:09 GMT
Hi KS.

The reason why dbconn is null must be when setting the session attribute.

Perhaps you got a ClassNotFound exception there. Are you sure that
DBConnection class is in the classpath for the Tomcat?

regards
Palle

> Hello,
>
[quoted text clipped - 13 lines]
> ....
> }
KS - 11 Sep 2003 18:45 GMT
Strange thing.
I didn't change anythig in the code or in the Tomcat or system settings and
it started working OK after 8 hours.
I don't know why, but it works now.

thx for your interest in helping me,
Krzysiek

> Hi KS.
>
[quoted text clipped - 23 lines]
> > ....
> > }
Carlo Pellegrini - 12 Sep 2003 09:02 GMT
> Strange thing.
> I didn't change anythig in the code or in the Tomcat or system settings and
> it started working OK after 8 hours.
> I don't know why, but it works now.
Be careful, when you store an Object in a session, it must
be Serializable.....
The Connection interface doesn't enforce it.

You should rely on the Tomcat connection pooling facility
instead:
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html

Regards,
   CarloP


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.