wood burning stoves 2.0*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "2 conditions to be checked" Watch "2 conditions to be checked" New topic
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 2 conditions to be checked
 
Similar Threads
Trying to grab the last record.
datas storing twice from servlet to mysql database
cookies problem
NULL POINTER eXCEPTION
Trying to grab the last record.