Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Java servlet and MySQL error

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I wrote the site, there should in the table bring the name of the students from the database (MySQL) + I can add the name of the new student to the database through the table and delete it. I wrote a servlet and JSP, but for some reason it does not work.

My Servlet (with requests)




JSP - AddStudent



JSP delete Student




Web XML

 
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Steve, welcome to the Ranch!

I didn't understand what you meant by "didn't work" -- that's not very specific. It would help if you explained what was supposed to happen, and what happened instead, and showed us what error messages appeared, and other things like that.

However I decided to give the code a quick scan and I noticed this:



So yes, that code does actually bring in the names of the students. However it doesn't do anything with the names.

But that really doesn't matter yet because it's in the show() method, and you never call that method.

And you mentioned a JSP: the one you posted has a form which sends a student's name via the POST method. However the doPost() method of your servlet doesn't have any code which adds a student to the database.

Also I noticed in your web.xml that your servlet isn't in a named package. Servlets must be in a named package.

There's likely more problems beyond that -- I think you have written far too much code before testing anything. I would suggest starting again with something simpler: perhaps a servlet which just outputs the names of the students?
 
Steve Gates
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:Hi Steve, welcome to the Ranch!

I didn't understand what you meant by "didn't work" -- that's not very specific. It would help if you explained what was supposed to happen, and what happened instead, and showed us what error messages appeared, and other things like that.

However I decided to give the code a quick scan and I noticed this:



So yes, that code does actually bring in the names of the students. However it doesn't do anything with the names.

But that really doesn't matter yet because it's in the show() method, and you never call that method.

And you mentioned a JSP: the one you posted has a form which sends a student's name via the POST method. However the doPost() method of your servlet doesn't have any code which adds a student to the database.

Also I noticed in your web.xml that your servlet isn't in a named package. Servlets must be in a named package.

There's likely more problems beyond that -- I think you have written far too much code before testing anything. I would suggest starting again with something simpler: perhaps a servlet which just outputs the names of the students?






Thank You)


I have already written a separate project and there he displays the names of the students.

Please can help write the code so that it prints the first and last names of students from my SQL database, and I can also add and remove students from the database.
 
Paul Clapham
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, we can help. But display-add-remove requires several servlets, although you could get away with only one JSP. So my suggestion was to start with one servlet, namely the one which displays the students.

Actually the first thing you should do is to design the JSP. So perhaps you could start with that? You won't be able to test it without writing a servlet, but as you may know, in computer programming it's better to design first and write code later.
 
Steve Gates
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Unfortunately, only one servlet is needed and there should be these requests
 
Paul Clapham
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Steve Gates wrote:Unfortunately, only one servlet is needed and there should be these requests



You want only one servlet but your requirements are that you need to be able to add students AND remove students? No, you should have a servlet which does nothing but add a student (and then forwards to a JSP which redisplays the remaining students). And you should have another servlet which does nothing but remove a student (and then forwards to that same JSP). That's just a basic design principle -- a component should do only one thing. If that "only one servlet" idea is coming from somebody else and you are being forced to do it that way, then I feel sorry for you.

Anyway, you already have my suggestion. Let me just add one thing more: you don't have to write the whole system before you start testing the code you wrote.
 
Steve Gates
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Please, you can write your version of the project.
 
Paul Clapham
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. That's not how the Ranch works. We aren't a code-writing service -- but we're definitely willing help people with code that they have written. So give it a try and then come back and ask about the code you've written.
 
Steve Gates
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The project that I wrote above cannot be corrected at all?
 
Paul Clapham
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may remember that I pointed out several problems with it already.
 
Sheriff
Posts: 21805
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Steve Gates
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I want to delete it through its id

MyServlet



Delete JSP

 
Saloon Keeper
Posts: 5815
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "I can't" mean? How are you executing any of this code, and what exactly happens as a result?
 
Steve Gates
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I change code

I can not delete a student from the database by id
My servlet
 
Rancher
Posts: 4278
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you get an error?
 
Tim Moores
Saloon Keeper
Posts: 5815
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:What does "I can't" mean? How are you executing any of this code, and what exactly happens as a result?



TellTheDetails
 
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!