Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

RMI return value

Posted on 2005-03-17
11
Medium Priority
?
215 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

571 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