session tracking in jsp

qurratulain's Avatar, Join Date: Oct 2006
Go4Expert Member
sir
i need help in session tracking in jsp form .in which Admin makes login to update the information. of student and teacher. session should be expire when he made log out.
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Here is an example code to use Sessions in JSP.

Code: JSP
<%@ page import="java.util.Enumeration" %>
<%!
  private static final String textname = "text";
  private static final String countname = "counter";
%>
<%
  Integer count = (Integer) session.getAttribute (countname);
  if (count == null)
    count = new Integer (0);
  String text = request.getParameter (textname);
  if (text == null)
    text = (String) session.getAttribute (textname);
  else
    {
      session.setAttribute (textname, text);
      count = new Integer (count.intValue () + 1);
      session.setAttribute (countname, count);
    }
%>
0
qurratulain's Avatar, Join Date: Oct 2006
Go4Expert Member
Quote:
Originally Posted by pradeep
Here is an example code to use Sessions in JSP.

Code: JSP
<%@ page import="java.util.Enumeration" %>
<%!
  private static final String textname = "text";
  private static final String countname = "counter";
%>
<%
  Integer count = (Integer) session.getAttribute (countname);
  if (count == null)
    count = new Integer (0);
  String text = request.getParameter (textname);
  if (text == null)
    text = (String) session.getAttribute (textname);
  else
    {
      session.setAttribute (textname, text);
      count = new Integer (count.intValue () + 1);
      session.setAttribute (countname, count);
    }
%>
sir i m having the problem in code for updating the teacher information in my project . i have two tables
(1)teacher-personal-info(id,name,address,age,phone,email);
(2)teacher-job(id,subjectid,salary,experience,date-of-joinig);


how can i made update in both tables while using the single query.i m using the access,jsp.
check pls if there is any problem.and also tell me how can i get the result from two tables through while(rs.next()){} and print it
.........code is here........
Code:
<%
String tid=request.getParameter("tid");
			
		String table=request.getParameter("table");
		
	//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

	//Connection con=DriverManager.getConnection("jdbc:odbc:school-db");

	//Statement stat=con.createStatement();
	
		//ResultSet rs;
	
	if(table.equals("teacher-personal-info")){
		
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

		Connection con=DriverManager.getConnection("jdbc:odbc:school-db");
		
		Statement stat=con.createStatement();
	
	ResultSet rs=stat.execute("select * from teacherinfo where tid like'"+tid+"'");
			while(rs.next()){
				String tid2=rs.getString(1);
				String name=rs.getString(2);
				String address=rs.getString(3);
				String phone=rs.getString(4);
				String cell=rs.getString(5);
				String email=rs.getString(6);
				
				
				
				}
		}
		
		
		if(table.equals("teacher-job-info")){

			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

			Connection con=DriverManager.getConnection("jdbc:odbc:school-db");

			Statement stat=con.createStatement();
	
			ResultSet rs= stat.execute("select * from teacher-job where tid='"+tid+"'");
			while(rs.next()){
				String tid2=rs.getString(1);
				String name=rs.getString(2);
				String address=rs.getString(3);
				String phone=rs.getString(4);
				String cell=rs.getString(5);
				String email=rs.getString(6);
				
				
				
				}
		}
	%>
			

	
<div id="text">
	<form action="http://localhost:8080/school-project/teacher/update2.jsp">
		<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
				<center>Add information
				
			</center><br/><br/><br/>
			<table border="0" id="text">
			<tr><td>Teacher-id&nbsp;</td><td><input type="text" name="tid" value="tid2"></td></tr>
			<tr><td>Name&nbsp;</td><td><input type="text" name="name" value="name"></td></tr>
			<tr><td>Address &nbsp;</td><td><input type="text" name="address" value="address"></td></tr>
			<tr><td>phonE&nbsp;</td><td><input type="text" name="Phone" value="phone"></td></tr>
			<tr><td>CELL# &nbsp;</td><td><input type="text" name="cellno" value="cell"></td></tr>
			<tr><td>&nbsp;E-mail &nbsp;</td><td><input type="text" name="email" value="email"></td></tr>
			
			</table>
			<center><input type="submit" value="update">
			<a href="teacher.html">back</a>
<br/><br/>
			</center>
	</form>

Last edited by shabbir; 24Dec2006 at 20:15.. Reason: Code formating.
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
You can get only one resultset for a single query, unless you join the tables.
I didn't get you point in executing 2 different queries. You can execute to as many queries as you want, but not in a single statement.