This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes help for jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "help for jdbc" Watch "help for jdbc" New topic
Author

help for jdbc

anwesh maity
Greenhorn

Joined: Oct 31, 2007
Posts: 20
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 ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41181
    
  45
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.


Ping & DNS - my free Android networking tools app
anwesh maity
Greenhorn

Joined: Oct 31, 2007
Posts: 20
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
Marshal

Joined: Mar 22, 2005
Posts: 41181
    
  45
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

Joined: Oct 31, 2007
Posts: 20
as soon as the debugger is reaching the line



it shows me session invalidated and the null pointer exception
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41181
    
  45
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

Joined: Oct 31, 2007
Posts: 20
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
Marshal

Joined: Mar 22, 2005
Posts: 41181
    
  45
That form doesn't contain a field called "employeelastname".
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459


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

Joined: Oct 31, 2007
Posts: 20
thanks a ton for your help i just figured out the problem and solved it.thank you for your co-operation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help for jdbc
 
Similar Threads
JDBC Connection
HTTP Status 404 - Servlet action is not available
Converting servlet to a WebSphere JDBC datasource
ClassNotFoundException while trying to connect to Oracle
Oracle Drivers