• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error loading the MySQL database table from a jsp  RSS feed

 
Dhavan Aryan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I m new to programming and am working on the college project. I have MySQL 5.6.20, Eclipse Kepler and Apache Tomcat 7.0.54. I m trying to retrieve the whole table from MySQL schema into a jsp. All the possible things i can do, i have already tried, but none of them are helping. The following attachment contains the whole project. I have my sql connection code in Sample.java file, which i want to get working in Fetch.jsp on the Submit button click. But it shows the tomcat error as localhost:8080/Sample HTTP Status 404-/Sample ; type Status report; message /Sample; Description The requested resource is not available.

The help will be very much appreciated ASAP,please!






 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your web.xml why the / preceding Sample in servlet-class? remove the / .. and think it should have the fully qualified class name

Also the action property should be preceded by the webapplication context? like /YourWebAppName/Sample

hope this helps..
 
Dhavan Aryan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Editing worked, i think. Removed / from servlet class and from action property. But this time the error is ClassNotFoundException which is called in the Sample.java class, meaning, the click event is NOW calling the class and then it is generating the exception. Suggest me, what to do NOW?
By the way, all the other fully qualified class names didn't work, just showed the Resource not available error!!
Help me on the exception error!
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your changes?
 
Dhavan Aryan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fetch.jsp



web.xml file



and the error message


 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The class should be fully qualified.. like this..

<servlet-class>testusecase.Sample</servlet-class>
 
Dhavan Aryan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gamini Sirisena wrote:The class should be fully qualified.. like this..

<servlet-class>testusecase.Sample</servlet-class>



Yeah,that helped.After this i m not getting any errors but just a blank page.Should i make another table in jsp form to fill in with the database table column entries?
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's take this step by step..

You are doing this..

RequestDispatcher view = req.getRequestDispatcher("Fetch.jsp");
view.forward(req, resp);


comment those lines for now. Browse the web to find how to print stuff to the browser from your servlet. Once you are successful with printing a test message you can try printing all results from your query to the browser.
we'll talk after that..
 
Dhavan Aryan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried simple plain text like "Hello" and also, i commented the RequestDispatcher as you said to try getting the simple output as text.It is working with the help of PrintWriter object, at both the places, outside and inside the try{}. But the real problem i can't figure out is about displaying the table of the database schema. What exactly is it that i should do now? Sorry to be such a pain, but really need your help with this. It's a small,college project and it's already high time. Please Guide me the changes in the servlet ASAP.
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to display results from your database query right?

Now the way you printed the "Hello" you can print each value to the browser.
If you want to display the data in a HTML table then you have to write that to the browser as wel..

like..


 
Dhavan Aryan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the mess and trouble, but just minutes ago, i finally found a way out to print table after your advice to start search from how to print simple text. Now the problem is regarding the empty/Null values present in the database. jsp output isn't showing rest of the records if it finds a Null value in the first row itself.

Example: Scenario 1:Here the first record doesn't contain any value for 12th percentage in the database. So the rest of the records aren't showing up at all.
Scenario 2:The record with Serial no 8 have null value for Middle name into the database and from there the rest of the table show drops off.
This was just to verify that the problem i think is exactly about the null values.
Scenario 2 is after commenting the code. The output contains some personal information, so the snapshots aren't included.Sorry!
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
with this
out.print((rs.getObject(1)).toString());

you are dereferencing g the object returned from the result set. Which would throw a null pointer Exception if it was null. I sugget you do.. for now.. which will handle the nulls.. (but will print null)

out.print((rs.getString(1)+""));

and aren't you seeing a null pointer stack trace in the console?
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Java Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having HTML code inside servlet, is not good.. You should learn JSP, and use JSTL and EL to display the data you want in the view.
Since you are learning now, start learning the good habits..
 
Dhavan Aryan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@GaminiSirisena, Sir, it sure works!! Thank you a lot.

@Prasad Krishnegowda...Thanks to you too. keeping that advice in mind, i am looking forward to learn it right away.
 
Gowtham Narendar
Greenhorn
Posts: 1
Eclipse IDE MySQL Database Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
There is a way to shorten your code and make it efficient. Try to use JSTL tag libraries. I use it all time and it works well.
 
ali issemgane
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, you have an HTML code inside your servlet, it's a bad practice You should learn JSP (JSP standared tag library) it will hep you to generate HTML code without using java code , also you can use JSTL inside your JSP pages try to learn this technologies, they wil help you .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!