Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question selection of records from table n applying a query on them

    Hi everyone I have a jsp code for attendance with access database.

    Basically the code is supposed to work like this:

    1. The teacher first enters information about the date ,semester , subject and time and submits.
    2. Then depending on semester..the SELECT query is used to obtain the list of all students from a STUDENT table for that semester. So now a form is filled with the relevant information and the teacher has to only enter the attendance for each student. Once she s done she submits all this.
    3. And the INSERT query is executed for table ATTENDANCE with the above info and the work is done

    Problem:

    Since there is a selective display of records from the STUDENT table using WHILE loop..the records are getting displayed. But only the first record is getting inserted after adding the attendance ..The rest are simply ignored. Maybe its because the form fields have the same names but have diff records for each loop which is not being accounted for. Maybe there is a need of arrays or counter somewhere..I don't know..Please suggest something..i have a project report coming up next week..i ll mail the code now..

  • #2
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re:

    code in the next post
    Last edited by silversurface; 02-19-2010 at 06:58 PM.

  • #3
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    INSERTATTEND.JSP [THE PREV FORM INFO IS COPIED HERE AND THE WHOLE INFO IS INSERTED IN THE ATTENDANCE TABLE]
    PHP Code:
    <body>
    <%
    ResultSet rs=null;
    try
    {Class.
    forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();

    Connection conn=DriverManager.getConnection("jdbcdbc:new2");

    Statement stmt conn.createStatement();
    String query= new String();
    String database="C:\\Database1.mdb";
    String rollno=request.getParameter("rollno");
    String time=request.getParameter"time" );
    String stat=request.getParameter"stat" );
    String sem=request.getParameter"sem" );

    rs=stmt.executeQuery("INSERT INTO Attendance VALUES('"+rollno+"','"+sub1+"' ,'"+sem+"',  '"+time+"', '"+stat+"')");
    rs.close();
    conn.close();
    }
    catch (
    SQLException e) {
    out.println("Error occurred " e);
    }

    int j=0;

    ResultSet rs1=null;

    try
    {
    Class.
    forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    Connection conn1=DriverManager.getConnection("jdbcdbc:new2");
    Statement stmt conn1.createStatement();
    out.println ("Database Connected.");
    String query= new String();
    String database="C:\\student1.mdb";
    String sem=request.getParameter("sem");
    String time=request.getParameter("time");
    String rollno=request.getParameter("rollno");
    String stat=request.getParameter("stat");
    rs1=stmt.executeQuery("SELECT * FROM Student where Sem='"+sem+"' ");
    %>

    <
    form name="input" method="get" action"insertattnd.jsp" Onsubmit="return validate_form(this)" >
    <
    table border=1 cellpadding=" 5" width="100" margin="25">
    <
    tr><thRoll_No </th> <th>Sem </th> <th> Class </th> <thDate </th> <thTime </th> <thSubject </th> <thLecture</th> <thAttendance </th> <thTeacher </th></tr>

    <%while (
    rs1.next())
    {
    j=j+1;
    %>
    <
    tr><td ><input type="text" name="rollno" value=<%out.println(rollno);%>></td>
    <
    td ><input type="text" name="sem" value=<%out.println(sem);%> ></td>

    <
    td ><input type="text" name="time" value=<%out.println(time);%> /> </td>
    <
    td> <input type="text" name="stat" value=<%out.println(stat);%> /> </td>
    <% }%>
    <
    tr> <td> <input type="Submit" name="submit" value="Submit"/></td></tr></table></form>
    %>
    <%
    rs1.close();
    conn1.close();
    }
    catch( 
    SQLException e)
    {
    out.println("Exception Occured "+e);
    }
    %>
    </
    body
    Last edited by silversurface; 02-18-2010 at 05:40 PM.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •