Friday, October 3, 2008
What Is A Mutual Fund
Use of jsp scriptlet to index jsp array variable in struts
For that first we have to declare the array variable in the java form bean with its getters and setters as given below.
int[]chkvalue=new int[20];
public int[] getChkvalue() {
return chkvalue;
}
public void setChkvalue(int[] chkvalue) {
this.chkvalue = chkvalue;
}
Now we can index the element using scriptlet as given below in the jsp page.
Note: Please careful about the quotes
<logic:present name="list">
<logic:iterate id="id" name="list" indexId="ctr">
<html:checkbox name="id" value="" property='<%="chkvalue["+ ctr+"]"%>'>
</html:checkbox>
</logic:iterate>
</logic:present>
Use of logic:iterate within table
<table>
<logic:present name="names">
<logic:iterate id="id" name="names" indexId="ctr">
<TR>
<TD >
<bean:write name="id" property="rollNumber" /></TD>
<TD>
<bean:write name="id" property="studentName" />
</TD>
</tr>
</logic:iterate>
</logic:present>
</table>
Using for loop a method returning arraylist in java struts using jdbc
Here is the sample method is given which is retuning the database values with the arraylist in which the for loop is used to execute the query multiple time.
public ArrayList
ArrayList
MYSQLConnect connect=new MYSQLConnect();
Connection conn = connect.connection;
Statement smt = conn.createStatement();
ResultSet rs = null;
//write select query for checking password
for(int i=0;i
{
String query="select SUM(attendance) As presenty,count(attendance)as
total,SUM(attendance)/count(attendance)*100 as percentage
from attendance where gr_number='"+grNumber[i]+"' and (Date
between '"+datefrom+"' and '"+dateto+"') order by `date` ";
rs=smt.executeQuery(query);
while(rs.next()== true){
StudentDetailsForm form =new StudentDetailsForm();
form.setPresentdays(rs.getInt("presenty"));
form.setTotaldays(rs.getInt("total"));
form.setAverage(rs.getInt("percentage"));
System.out.println(rs.getInt("percentage"));
list.add(form);
}
}
smt.close();
rs.close();
conn.close();
return list;
}
Inserting database values into the String array in java struts using jdbc
Here is the sample method code is given which is inserting the database values in String array variable.
public String[] findGRNumbers(String branch,String course,String trimester,int size) throws DataAccessException,java.sql.SQLException{
MYSQLConnect connect=new MYSQLConnect();
Connection conn = connect.connection;
Statement smt = conn.createStatement();
ResultSet rs;
int no=0;
String[]str=new String[size];
//write select query for checking password
String query="select gr_number,roll_number,student_name from
student_master where branch='"+branch+"' and
course='"+course+"' and trimester='"+trimester+"'";
rs=smt.executeQuery(query);
while(rs.next()== true){
str[no]=rs.getString("gr_number");
no++;
}
smt.close();
rs.close();
conn.close();
return str;
}
Making a method returning arraylist in java Struts using jdbc
Here is the sample method is given which is retuning the database values with the arraylist.
public ArrayList
ArrayList
MYSQLConnect connect=new MYSQLConnect();
Connection conn = connect.connection;
Statement smt = conn.createStatement();
ResultSet rs;
//int no=0;
//String[]str=new String[20];
//write select query for checking password
String query="select DISTINCT `date` from attendance where (Date between
'"+datefrom+"' and '"+dateto+"')";
rs=smt.executeQuery(query);
while(rs.next()== true){
StudentDetailsForm form =new StudentDetailsForm();
form.setDateFrom(rs.getString("date"));
list1.add(form);
}
smt.close();
rs.close();
conn.close();
return list1;
}