?
Solved

RMI return value

Posted on 2005-03-17
11
Medium Priority
?
214 Views
Last Modified: 2010-03-31
Hi,
I was trying to use the user entered id and password from a logon method and verify if they exist.

It seems that the program is returning false even if the user exists in the database.
There must be some logical error with my Implementation method..
Could you please check what the error could be.
>>>
If the user exists, I would like return true, if not then false.
Here is the method that returns the boolen value:

public boolean verify(int ID, String password){
            try{
                  Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
                  connection = DriverManager.getConnection(
                  url, username, password );
                  String sql = "SELECT UST_ID, PASSWORD FROM STUDENT WHERE UST_ID = ? and PASSWORD = ?";
                  PreparedStatement ps = connection.prepareStatement(sql);
                  ps.setInt(1, ID);
                  ps.setString(2, "password");
                  ps.executeQuery();
                  ResultSet rs = ps.executeQuery();
                  if (rs.next())
                       // valid
                       return true;
                     System.out.println("GET LOST FRED");
                  

                  }


            catch ( ClassNotFoundException cnfex ) {
                  System.err.println(
                  "Failed to load JDBC/ODBC driver." );
                  cnfex.printStackTrace();
                  System.exit( 1 );  // terminate program
                                                }
            catch ( SQLException sqlex ) {
                  System.err.println( "Unable to connect" );
                  sqlex.printStackTrace();
                  System.exit( 1 );  // terminate program
                  }

                  return false; //???????

      }


Thanks.
_Esam
0
Comment
Question by:_Esam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 6

Expert Comment

by:durgaprasad_j
ID: 13572105
hi,
why can you just use

String sql = "SELECT UST_ID, PASSWORD FROM STUDENT WHERE UST_ID ="+ID+" and PASSWORD = \'"+password+"\'";
PreparedStatement ps = connection.prepareStatement(sql);
 ResultSet rs = ps.executeQuery();
0
 
LVL 6

Accepted Solution

by:
durgaprasad_j earned 200 total points
ID: 13572162
hi,
what you have done previously is 100% right. but a small mistake

 String sql = "SELECT UST_ID, PASSWORD FROM STUDENT WHERE UST_ID = ? and PASSWORD = ?";
               PreparedStatement ps = connection.prepareStatement(sql);
               ps.setInt(1, ID);
               ps.setString(2, "password");

Should be

 String sql = "SELECT UST_ID, PASSWORD FROM STUDENT WHERE UST_ID = ? and PASSWORD = ?";
               PreparedStatement ps = connection.prepareStatement(sql);
               ps.setInt(1, ID);
               ps.setString(2, password);

Hope this helps
DP
0
 

Author Comment

by:_Esam
ID: 13572165
Ok,
If i try it like yours.
And if have a client method where I verify it like:

final boolean userVerified = (myServerObject.verify(id, password));

What 's gonna happen?

My question was:
The return value???

I don't see any return value in your code.
Or I don't understand. :)

_Esam
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:_Esam
ID: 13572177
So,
It was just this part:
>>  ps.setString(2, "password");
should be: >>   ps.setString(2, password);

??
_Esam
0
 
LVL 6

Expert Comment

by:durgaprasad_j
ID: 13572193
hi, see my second comment.
you are passing the password as "password", but  not the value of password argument.

In my first comment, you can use that to pass the password parameter value directly. even that was correct.

And in your main post, you executedquery twice. you dont need to execute it twice. once is enough.

DP
0
 

Author Comment

by:_Esam
ID: 13572212
Hi,
Yes, I understood your > parameter passing directly
And >>you are passing the password as "password", but  not the value of password argument << I undertood this part now.
Also>>And in your main post, you executedquery twice. you dont need to execute it twice. once is enough.

So, my return sequences was OK?? (This was my most concern) :)
Please let me know.

Thanks.

_Esam
0
 
LVL 6

Expert Comment

by:durgaprasad_j
ID: 13572239
yes, it should be ok.

you execute SELECT UST_ID, PASSWORD FROM STUDENT WHERE UST_ID = <someid> and PASSWORD = <somepassword> in database manually, if that sql is working fine, it should not give any errors in the program also.

DP
0
 

Author Comment

by:_Esam
ID: 13572251
Hi durgaprasad,,
Yes, you are right.
I just recompiled and run it, and it's working.  :)
Thank you

_Esam
0
 
LVL 6

Expert Comment

by:durgaprasad_j
ID: 13572256
:) , just see your previous post on rmi binding error, that also might be because this simple mistake in this sql statement.
0
 

Author Comment

by:_Esam
ID: 13572257
I will be working on this problem for a while..
Might encounter some problems, hope not :)
Might ask some more question if I come accross ..

Thax.
_Esam
0
 

Author Comment

by:_Esam
ID: 13572273
Yes, you are right....  I had to many problems getting some results from the RMI...
Well, the problem was when I started using GUI for the client side..:)
It was giving me results when I hardcoded the id (on the client side) and when I was not using the verify method from the Interface.
I just directly invoked some other methods with a hardcode id as an int , and it was working...
Not it's working with the verify method also..
A greate help..

Thanks.
_Esam
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question