Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-18-2010, 07:27 AM   PM User | #1
silversurface
New to the CF scene

 
Join Date: Feb 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
silversurface is an unknown quantity at this point
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..
silversurface is offline   Reply With Quote
Old 02-18-2010, 07:30 AM   PM User | #2
silversurface
New to the CF scene

 
Join Date: Feb 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
silversurface is an unknown quantity at this point
Re:

code in the next post

Last edited by silversurface; 02-19-2010 at 05:58 PM..
silversurface is offline   Reply With Quote
Old 02-18-2010, 04:30 PM   PM User | #3
silversurface
New to the CF scene

 
Join Date: Feb 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
silversurface is an unknown quantity at this point
Quote:
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 04:40 PM..
silversurface is offline   Reply With Quote
Reply

Bookmarks

Tags
access, insert, jsp, query, while loop

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:27 AM.


Advertisement
Log in to turn off these ads.