File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes 2 conditions to be checked Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "2 conditions to be checked" Watch "2 conditions to be checked" New topic

2 conditions to be checked

sunita shaw
Ranch Hand

Joined: Apr 06, 2003
Posts: 45
i want to check for two conditions i.e if the username that i have entered in the text field exist or not & also if he is an admin or user,if true then procced further with the code,i tried tghis but i'm getting an error.can anyone help me with it...
Connection conn = null;
String seq = "";
int seqint = 0;
String uniqueid,username="",status="",access = "";
int intuniqueid = 0;
conn = DriverManager.getConnection("jdbc dbc:trying","", "");
Statement stmt = conn.createStatement();
//unique id is stored from the session
uniqueid = (session.getAttribute( "UniqueID")).toString() ;
intuniqueid = Integer.parseInt(uniqueid);
String deleteuser = "Select access, user_name from login1 where unique_user_id = " + intuniqueid;
ResultSet rs1 = stmt.executeQuery(deleteuser) ;
username = rs1.getString("user_name");
access = rs1.getString("access");
if( access.equals("admin"))
Statement stmt1 = conn.createStatement();
stmt1.executeUpdate("update login1 set status = '(Gone)' where unique_user_id = " + rs1.getString(1));
out.println("Please enter User Name correctly");
out.println("Really Sorry you are not authorized to change password, try to login through Admin");
}catch (Exception ex) {
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
What is the error you are getting, could you display the error message?
Dave Mulligan

Joined: Mar 14, 2003
Posts: 18
You could try something like this, assuming that you are enforcing unique user IDs (ie a SELECT statement using UserID will return either zero or one rows):

You'll need to create the NoSuchUserException class - just extend Exception.
On another note, you might want to try pulling this code out of the JSP into a bean, a servlet, or even a custom tag to improve re-usability in case you need this functionality on another page, and to help with the maintainance of your JSP.
Hope this helps
[ April 15, 2003: Message edited by: Dave Mulligan ]
I agree. Here's the link:
subject: 2 conditions to be checked
It's not a secret anymore!