File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Problems with DB access in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problems with DB access in servlet" Watch "Problems with DB access in servlet" New topic
Author

Problems with DB access in servlet

jonas okwara
Ranch Hand

Joined: Jun 22, 2004
Posts: 58
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

Joined: Jan 10, 2002
Posts: 60782
    
  65

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.


  • [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60782
        
      65

    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

    Joined: Jan 10, 2002
    Posts: 60782
        
      65

    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

    Joined: Jan 10, 2002
    Posts: 60782
        
      65

    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

    Joined: Jan 28, 2008
    Posts: 5575

    another thing, getting datas should be inside doGet, not in doPost.
    jonas okwara
    Ranch Hand

    Joined: Jun 22, 2004
    Posts: 58

    Thanks seetharaman for your observation.
    Jonas
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60782
        
      65

    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

    Joined: Aug 09, 2012
    Posts: 179
    Hi,

    As for the problem.I can see

    jonas okwara wrote:


    this is the problematic line.

    Try

    instead.

    Programming is about thinking, NOT coding
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Problems with DB access in servlet
     
    Similar Threads
    user authentication and dao
    Jsp Login Page Problem
    'The requested resource is not available' error
    Httpsesion Listener is not working properly?
    user authentication servlet problem