• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with DB access in servlet

 
jonas okwara
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am pretty new to Java Servlets and I Need to be pointed to the right direction. I am writing a login servlet which somehow does not appear to be querying the database.

Please some directions as to what I am doing wrong.

Thanks
Jonas

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A couple of things to help you get better and faster answers:

  • Please be sure to take the time to compose descriptive subjects for your posts. You will attract people who will can give you better and faster answers when your posts have good, descriptive subjects. For more information, please click this link ⇒ UseAMeaningfulSubjectLine. Using a title of "Servlet" in a forum completely dedicated to questions on servlets isn't going to attract the attention of those who can best help you.

    I have changed the subject to one that's more suitable; please use it as an example for future posts.


  • Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.

    I've gone ahead and added the code tags for you. See how much easier the code is to read? Though it would be much easier if you used proper indentation in your code.
  •  
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 64718
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Have you tried using logging or a debugger to try and find out at what point the code is deviating from the expected actions?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 64718
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    jonas okwara wrote:I am pretty new to Java Servlets and I Need to be pointed to the right direction.

    Once the DB code is working, the right direction would be to remove this code from the servlet itself. It should be delegated to a class in your model.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 64718
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    And here's another anti-pattern:

    Your code eats the exception. So what happens to the response in such a case?

    In a web app, exceptions should be allowed to propagate outwards until they reach a central error handler defined in the deployment descriptor that can show a user-freindly "oops" page to the user, while logging the error properly for development to diagnose.
     
    Seetharaman Venkatasamy
    Ranch Hand
    Posts: 5575
    Eclipse IDE Java Windows XP
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    another thing, getting datas should be inside doGet, not in doPost.
     
    jonas okwara
    Ranch Hand
    Posts: 58
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Thanks seetharaman for your observation.
    Jonas
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 64718
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Seetharaman Venkatasamy wrote:another thing, getting datas should be inside doGet, not in doPost.

    That is not always a true statement. It depends upon the purpose of the request -- not whether data is fetched from the DB or not.
     
    Vishal Shaw
    Ranch Hand
    Posts: 179
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,

    As for the problem.I can see

    jonas okwara wrote:


    this is the problematic line.

    Try

    instead.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic