• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help for jdbc

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a jsp page which has backing bean in java


the source code for it is given below




i m getting a null poitner exception for this please let me know why i am getting so???
[ March 25, 2008: Message edited by: Ulf Dittmer ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's too much code to look through and guess what the problem might be. In which line does the exception occur?

Also, when posting code of any length, please UseCodeTags. I have added them to your code, because otherwise it is just not comprehensible.
 
anwesh maity
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
while debugging i am able to debug till the employee last name but as soon as it goes to debug the states it shows me session invalidated with a java.lang.nullpointer exception
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Several issues jumped out at me, which may not be related to the problem, but should be fixed regardless. (You didn't mention which line the exception occurs in, and which object is null).

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());


This should be done once in initialization code, not repeatedly every time the page is shown.

conn.setAutoCommit(false);


For a single insert you do not need to use a transaction. Either the insert succeeds or it fails (in which case you'll get an exception) - no need for a transaction.

if (citycode == "" || citycode == null)


if (usernames == userName)

(multiple occurrences)
You should test for null first, and then perform other tests. Also, strings are compared using the "equals" method, not using "==" (which compares equality of object references, not equality of objects). So this code should read
 
anwesh maity
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as soon as the debugger is reaching the line



it shows me session invalidated and the null pointer exception
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So which object is null: view, state1, or state1.getValue()?

Does the form have the field called "state1" (earlier you were using "state" and "states")?
 
anwesh maity
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is ma jsp page



and i have made the certain changes according to it in the java bean also changing the "state" to "states1" ..... no value is zero over here as soon as it reaches the line in the java bean



it comes out and the debugger doesn't reaches the line
states line in the java bean
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That form doesn't contain a field called "employeelastname".
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This is NOT the same as exception handling, this is NOT the same as resource cleaning.

Always close your connections, always close your streams.


If you're not going to manage an exception(e.printStackTrace() is not sufficient, and not useful) then throw it from the method.
 
anwesh maity
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a ton for your help i just figured out the problem and solved it.thank you for your co-operation
reply
    Bookmark Topic Watch Topic
  • New Topic