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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unable to get desired result,after comparing values from database.

 
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I am very much new to the web development world,so there are chances that i might be missing a simple point.

I am working on NetBeans IDE 7.1

This is the first page of my project



Now the servlet which is hit,when the form of above html is submitted:






UserDAO class is:


and User class is:


My problem:
In the table(inside database) if i put a record and when while interacting with the web-tier i put the same data still the output i get is:




for example:
in table if i put rollno=1318710085
and password=abc

Still in the form if i put the same value
the output will be
 
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Have you confirmed that a database record exists with rollno='1318710085' and password='abc'?

Have you checked the webserver log to see if an exception was thrown and caught in UserDAO?
 
Sachin Tripathi
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Ron McLeod wrote:Have you confirmed that a database record exists with rollno='1318710085' and password='abc'?



yes, i did

Ron McLeod wrote:Have you checked the webserver log to see if an exception was thrown and caught in UserDAO?



not sure,what this mean,but UserDAO class was error less
 
Ron McLeod
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Sachin Tripathi wrote:

Ron McLeod wrote:Have you checked the webserver log to see if an exception was thrown and caught in UserDAO?


not sure,what this mean,but UserDAO class was error less


In the searchUser method in your UserDAO class, you have a catch block which writes to stdout. If you had an exception anywhere before you call the constructor for User, that method would return null. You need to trackdown where stdout gets written to, and see if there was any indication of an exception being caught.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
In fact, don't catch the exception! If you don't have anything useful to do, let the exception bubble out to the container so it can report it.
 
Sachin Tripathi
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Did this,but still no change:

(in UserDAO)

and in servlet:

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
How is that supposed to change anything?
 
Ron McLeod
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
You are still catching it in your method and not letting it propogate upwards.
 
Sachin Tripathi
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Don't know,was just making sure that exception do get displayed..

(I know it does not make any difference though )
 
Sachin Tripathi
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Bear Bibeault wrote:In fact, don't catch the exception! If you don't have anything useful to do, let the exception bubble out to the container so it can report it.



What if it is checked one?
 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Sachin Tripathi wrote:What if it is checked one?


Then "throws" comes to the rescue.
 
Sachin Tripathi
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Tapas Chand wrote:
Then "throws" comes to the rescue.



So still we have to do all the same things from where we call the method which throws.Don't we?
 
Tapas Chand
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Sorry, did not check previous posts carefully.
Well you can throw an exception from Servlet also instead of catching it.

Note that doGet() and doPost() are already throwing ServletException and IOException.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
ServletException is intended as a wrapper.
 
Ron McLeod
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Sachin - please do let us know what you end-up finding and what you did to resolve your problem.
 
Sachin Tripathi
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Sorry for late reply,was busy with something

There was no error in any of my code
Actually I forgot to add oracle jar folder to my project library
 
Ron McLeod
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Did that result in a ClassNotFoundException being thrown in your searchUser method?
 
Sachin Tripathi
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Yes.
 
Sachin Tripathi
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
UserDAO class



Actually in the same project as discussed above, i have to maintain separate tables(in database) for different years.New year starts from August.
But have problem,while i run the project, i get this :

Welcome Mr. java.lang.NullPointerException,You are in 1 year and your rollnumber is 1
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Sachin,
This construct is hiding the information about which line is throwing the NullPointer. Can you add a e.printStackStrace() in the catch block and note which line is giving the error?
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I suspect the line with the problem is


You have four if statements that aren't mutually exclusive. I'd recommend making them a chain if if/else if statements. Also, what do you want to happen if none of the conditions match? Right now, you throw a NullPointer which is less than desirable.
 
Sachin Tripathi
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
How are they not mutually exclusive
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Sachin Tripathi wrote:How are they not mutually exclusive


That wasn't the right word. I meant there are cases they don't cover. In particular, if cMonth >= 8 or diff < 0 or diff > 3
 
Sachin Tripathi
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
yeah actually the problem was: on inputting value through web tier ,it was always going to case which is not mentioned;

Had some logical errors,modified them,now it works fine



Thanks
 
Sachin Tripathi
Ranch Hand
Posts: 373
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I have problem in the same project.
Now i am working on home page(displayed after loging in)
for that am planning to do something like this:

  • First the user selects the year of his course,
  • then he should get option to select the branch(electrical,electronics etc)
  • then he should get option of subjects of that branch(many subjects are mutually exclusive,with respect to branch)
  • then all study materials regarding that subjects


  • must be shown.


    Actually have really no idea,how to do this,any sort of guidance would be appreciated
     
    Tapas Chand
    Ranch Hand
    Posts: 624
    9
    BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Report post to moderator
    JQuery + AJAX is a good option.
    I believe 'Year of course' is a dropdown box.
    If so, you can capture the 'onchange' event of that dropdown and fetch the 'branch'es from server. and so on...
     
    Sachin Tripathi
    Ranch Hand
    Posts: 373
    3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Report post to moderator
    Do I have to read whole ajax and jquery thing(I know nothing about them)
    Or can you tell me some specific portions to read?
     
    Bear Bibeault
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Report post to moderator
    As you have also posted this in another forum, I have closed this topic.
     
    Don't get me started about those stupid light bulbs.
      Bookmark Topic Watch Topic
    • New Topic