| Author |
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; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 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) ; while(rs1.next()) { username = rs1.getString("user_name"); access = rs1.getString("access"); } if( access.equals("admin")) { if(username.equals(request.getParameter("user_name"))) { Statement stmt1 = conn.createStatement(); stmt1.executeUpdate("update login1 set status = '(Gone)' where unique_user_id = " + rs1.getString(1)); } else out.println("Please enter User Name correctly"); } else { out.println("Really Sorry you are not authorized to change password, try to login through Admin"); } }catch (Exception ex) { out.println(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
Greenhorn
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 Dave [ April 15, 2003: Message edited by: Dave Mulligan ]
|
 |
 |
|
|
subject: 2 conditions to be checked
|
|
|