I have a login form in JSP. All the login information I'm storing in Oracle database.
For new users they need to register to login. But for the users those who have accounts, as they logs in they will have the option called "Account Setting" where they can edit their basic information.
When user clicks on that link, his account information should be displayed. But I'm not able to retrieve currently logged in user's information from database.
Here is my JSP code to check whether user's account exists or not:
<%
try
{
String user=request.getParameter("username");
String pass=request.getParameter("password");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","manager");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from student where
username='"+user+"' and
password='"+pass+"'");
int count=0;
while(rs.next())
{
count++;
}
if(count>0)
{
out.println("welcome "+user);
}
else
{
response.sendRedirect("studentlogin.jsp");
}
}
catch(Exception e)
{
out.println(e);
}
%>
<a href="settings_std.jsp">Account Setting</a>
If the user is valid then he can see the option "Account setting". i.e.
<%
String username=request.getParameter("username");
Connection con=null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con =DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system",
"manager");
Statement
st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=st.executeQuery("select * from from student where
username='"+username+"'");
if(rs.next())
{
%>
<h3>Your Account Information</h3>
<table>
<tr><td>Name:</td><td><input type="text" name="name" value=" <%=rs.getString("name")%>"></td></tr>
<tr><td>Degree:</td><td><input type="text" name="degree" value="<%=rs.getString("degree")%>"></td></tr>
<tr><td>Semester:</td><td><input type="text" name="semester" value="<%=rs.getString("semester")%>"></td></tr>
<tr><td>Branch</td><td><input type="text" name="branch" value="<%=rs.getString("branch")%>"></td></tr>
<tr><td>Contact No:</td><td><input type="text" name="mobile" value="<%=rs.getString("mobile")%>"></td></tr>
<tr><td>Email:</td><td><input type="text" name="email"
value="<%=rs.getString("email")%>"></td></tr>
<tr><td>Password:</td><td><input type="text" name="password" value="<%=rs.getString("password")%>"></td></tr>
</table>
<%
}
con.close();
}
%>
Hope somebody knows this. Thank you.