aspose file tools
The moose likes JDBC and the fly likes execute method in SQl Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "execute method in SQl" Watch "execute method in SQl" New topic
Author

execute method in SQl

dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
hi all

i am trying to create a login form
in which i take user name ,email id and password.
if the user is registered user the name ,id and password
are stored into database in table.So when the user logs in
i wanted to check by traversing through the database
that the name and password are right so previuosly
i was using
ResultSet rs;
rs.next(); method so it traverses
through all the registered name in database
but i felt this as abit long
so i choose execute () method which returns boolean value
if it gets the exact name and password but

below is my method



each time the query gets executed
if the user is not registered ie user name is not present
in the database then also i am getting value of b=true
whereas i expect if user name and password is not present
it must give b=false.


i dont know where i am going wrong ?

may be the method which i have used is not appropriate
for use at this place.........


Anyone can help me on to what i must use
or where i am going wrong it will be realy great
thanks in advance.............

Dhwani:>Its always too soon to quit.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1076

Dhwani As per java-docs

boolean execute(String sql)throws SQLException

Returns:
true if the first result is a ResultSet object; false if it is an update count or there are no results


therefore if your query is executed successfully then It will definitely return a resultset.

If there are no matching rows as per given criteria resultset.next() will be false. That is why you get true every time.

you modify your code
as





Thanks,
Shailesh
[ February 04, 2008: Message edited by: Shailesh Chandra ]

Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
hi shailesh!!!

Thanks for such a great reponse

i modified the query as shown by you as below

but i am stuck now somewhere else



i am storing this values when the user registers
in a table ,and when the user logs in the name and password is getting
verified in my query above
when i use statement as


but i want to verify not only name before logging in
but also password so i used query as


any help on the above will be
realy great

thanks in advance!!

Dhwani:>Winning is not important but it is the only thing.
[ February 04, 2008: Message edited by: dhwani mathur ]
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1076

  • Check the case-sensitivity of the password
  • user out.println to print your query, which is formed by code, and execute same or sql console


  • dhwani,

    validate above mentioned steps


    Thanks,
    Shailesh
    dhwani mathur
    Ranch Hand

    Joined: May 08, 2007
    Posts: 621
    Hi shailesh!!

    Thanks a lot
    my problem is solved......


    Dhwani:>Winning is not important but it is the only thing.
    [ February 06, 2008: Message edited by: dhwani mathur ]
    Shailesh Chandra
    Ranch Hand

    Joined: Aug 13, 2004
    Posts: 1076

    glad to know that its working now


    Thanks,
    Shailesh
     
    I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
     
    subject: execute method in SQl
     
    Similar Threads
    HTTP status 500
    JSTL Syntax
    data not persisted using hibernate spring integration
    Struts2-requested list key 'state' could not be resolved as a collection/array/map/enumeration/
    Record Locking in multi-user