Hello friends ,
I am trying to develop a web app that will show flight timings of different airports...
but i am having the following error when running servlet...
the interface is basic from beer application in headfirst but i was trying a test run
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
Null pointer exceptions occur when you try to call a method on an object when the object is null.
Your error message told you that this occurred on line 34.
Do you have a variable on line 34?
Are you trying to call a method of the object pointed to by that variable?
yeah it is the case the data you are trying to fetch from database might be null.you should check that what values it is getting by printing on console .
regards
Raza!
Good luck!!
A small leak can sink a Gigantic ship.>
i have used these class files from command prompt and they were returning values..
its only creating problems when i started using a servlet for retrieving values
The initial exception occurs on Line 34 of your AirPortDD.java file.... that is in the general areas of the attempt to access the result set....
Did you get the output from line 96 here in AirPortDD.java? which is the error from an exception trying to retrieve the result set in the first place....
There is so much wrong with this code from a design point of view... no closing of connections, no closing of statements.... Bad handling of exceptions....
some where object is not initialized.
best way is to run un debug mode or print incremental integers in the doubted line..by that you will get to know where exactly your code got struck.
the problem is that nothing is being added to the ArrayList..
is there any problem with the logic??
the servlet creates an object of class AirportDD , having a varaible of type List code.
the function is called and the function instantiates code as an arraylist and adds some string to it...
will the servlet have the same list as the attribute of the object it created ???
can any one help....
problem is that resultset is returning nothing when run from a servlet but it
returns the desired values when the same function is run from different class' main
If the NPE is being thrown on a line that contains only a rs.next() statement, then the problem isn't that the resultSet is returning nothing.
It's that the resultSet variable "rs" is null.
This means that your problem is happening before you get to that line.
You've got print statements in all of your catch blocks.
I suggest you clear all of your logs, run it again until it breaks and go through them to see what else is being thrown before you try to call rs.next().
If I had to take a wild guess it would be that the app can't find your JDBC driver.
You might want to do something more in your catch block than just log errors.
If you can't make the database call, your app should be dying before you try to read from the resultSet.
i tried the following program to check the problem
and the exceptions were can anyone explain how to correct this??
result is
Good till now
SQLException is this: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified SQLState : IM002 VendorError: 0
Hello World. Sun... 1.4
the initial problem was removed by making a system DSN.
the servlet is getting values ..and page is generated.
but there is a new sort of problem now..
when i start the database and the tomcat and load the page , the values are shown just fine but if i refresh the page 4-5 times
the servlet starts giving the same exception all over again..
i suspect its because not clossing connections as mentioned by Ben
can someone suggest me how to close connection in respect to the code AirportDD.java
as i am using different functions...
Do you have a good reason for using different methods?
Typically a database call is laid out like this:
The finally block will always get executed, even if something blows up in the try or catch blocks.
This guarantees that your connections will always get closed.
If you're not closing them, your app will work for a while.
Then, when you've hit the maximum number of open connections, it will fail.
do you mean running directly sql command in oracle...??
yes they run just fine...
they are running with servlet as well but due to not closing of connections, it gives NPE