debasis
urgentt
1 Answer(s)      6 years and 9 months ago
Posted in : Design concepts & design patterns
Dear Sir,
I have a table for students' details in a school.unique is their roll number in rows.coloumns are age,sex,grade etc.There is one coloumn vacant for lot no.I want to place equal number of students under one lot number.Then same numbers under another.If there is 60 stuednts.Group them as a,b,c,d,e,f.six group.60/10=6.For the first 10 studets lot no should be generated randomly and should be same.Next 10 students should have same lot no with random generation.User should enter his?her desired lot no after seeing number of records.e.g_if user sees ,there is 54 records,and wants to devide them in 6 groups with 9 students in each group.He/she should enter lot size=6.after saving that number the records should be automatically devided into 6 groups with generation of random numbers with same for 1st 9 students,then same for next 9.but user should calculate the groups he wants to devide.No pagination required.Lot no may vary from user to user and data may be different.might be 60 records or 81.81 means,if he enters lot no=9,9 records under one lot number

Enter LOT size you want:text box .Save button
RollNo Age Sex Location Lot No
452345 4 M ty Empty
545454 6 M 5y Empty
767568 7 M hy Empty
203392 9 M ty Empty
After entering 2,recodrs should be devided into 2 groups with generation of same lot no for first two,and same for next two records.This design is final.please help me.Likewise we can create for 20,30,40 students.

You asked me whether i want to use database?
Yes,lot number will be stored in database or by storing in a variable we can devide with number of records,and by that modulus we can create random numbers by running that loop by putting that result.But,records i am able to fetch from database.after that, i am not able to create random numbers by the above process.Any design ,you think valid,plizz give me..Thank you

Regards
Debasis Mohapatra

July 30, 2010 at 1:18 PM

Hi Friend,

Try the following code:

1)student.jsp:

<[email protected] import="java.sql.*"%>
<script>
function hello(){
var i=0,j=0;
var total=document.form.count.value;
var lsize=document.getElementById("lotSize").value;
var l=Number(total)/Number(lsize);
arr = new Array();
arr1=new Array();
for(i=0;i<lsize;i++)
{
arr.push(Math.floor(Math.random()*10) + 1);
}
for(j=0;j<arr.length;j++){
for(i=0;i<l;i++)
{
arr1.push(arr[j]);
}
}
var labels=document.getElementsByName("lot");
for(j=0;j<total;j++){
labels[j].value=arr1[j];
}
}
</script>
Enter LOT size you want:<input type="text" id="lotSize"><input type="button" value="Save" onclick="hello();"><br>
<form name="form" action="insertLot.jsp">
<table border="1">
<tr><th>Roll No</th><th>Age</th><th>Gender</th><th>Location</th><th>Location</th></tr>
<%Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("select * from student");
int i=0;
while(rs.next()){
%>
<tr><td><input type="text" value="<%=rs.getString("rollNo")%>" name="roll"></td><td><input type="text" value="<%=rs.getString("age")%>" name="age"></td><td><input type="text" value="<%=rs.getString("gender")%>" name="gender"></td><td><input type="text" value="<%=rs.getString("address")%>" name="address"></td><td><input type="text" name="lot"></td>
</tr>
<%
i++;
}
%>

<input type="hidden" value="<%=i%>" name="count">
</table>
<input type="submit" value="Submit">
</form>

2)insertLot.jsp:

<[email protected] import="java.sql.*"%>
<%
String roll[]=request.getParameterValues("roll");
String lot[]=request.getParameterValues("lot");

Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
Statement st = con.createStatement();
for(int i=0;i<roll.length;i++){
String rollNo=roll[i];
String lotNo=lot[i];
st.executeUpdate("update student set lotNo='"+lotNo+"' where rollNo='"+rollNo+"'");
out.println("Updated Successfully");
}
%>

Thanks