Hi
My requirement is to retrive data from the database and show it in atabular format in a
jsp page i have done that in this fashion,can any one help me how to use the tags .
package com.xxx.control;
import com.xxx.beans.TestCaseBean;
import com.xxx.entities.DBConnection;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
public class TestCase {
public ArrayList
test() throws SQLException{
ArrayList al = new ArrayList();
try{
//getting connection--------------
Connection connection =DBConnection.getConnection();
System.out.println("Connection in testcase"+connection);
String query ="select name ,description,id,status,testsuiteid,testprocedureid, to_char(cdate,'mm/dd/yyyy') ,complete,revision,environment,to_char(start_date,'mm/dd/yyyy'),to_char(end_date,'mm/dd/yyyy'),planned_testcases,completed_testcases,failed,sucess,defects from testcase";
ResultSet rs = null;
Statement st =null;
st =connection.createStatement();
rs = st.executeQuery(query);
while (rs.next()){
TestCaseBean tc = new TestCaseBean();
tc.setCdate(rs.getString(7));
tc.setDescription(rs.getString(2));
tc.setStatus(rs.getString(4));
tc.setRevision(rs.getString(9));
tc.setEnvironment(rs.getString(10));
tc.setStart_date(rs.getString(11));
tc.setEnd_date(rs.getString(12));
tc.setCompleted_testcases(rs.getInt(13));
tc.setPlanned_testcases(rs.getInt(14));
tc.setFailed(rs.getInt(15));
tc.setDefects(rs.getInt(17));
double comp;
comp = complete(rs.getInt(13),rs.getInt(14));
String cpl = comp+"%";
tc.setValue(comp);
System.out.println("*****************"+cpl);
double sr;
if(rs.getInt(14) == 0){
sr = 0;
}else{
sr = sucessratio(rs.getInt(13), rs.getInt(14),rs.getInt(15));
}
tc.setPercent(sr);
String sur = sr + "%";
System.out.println("*****************"+sur);
al.add(tc);
}
}
catch(Exception e)
{e.printStackTrace();}
return al;
}
public double sucessratio(int Completed_testcases,int Planned_testcases ,int failed){
double percent = ((double)(Planned_testcases-failed)/(double)(Completed_testcases))*100;
System.out.println("PERCENT int "+percent);
return percent;
}
public double complete(int Completed_testcases,int Planned_testcases){
System.out.println("PT : " + Planned_testcases);
System.out.println("CT : " + Completed_testcases);
double value = (((double)(Planned_testcases)*100)/(double)(Completed_testcases));
System.out.println("Value of Completed Percent"+ value);
return value;
}
}
-----------------------Bean class for the above --------------------
package com.osius.beans;
public class TestCaseBean {
private String Name;
private String description;
private int id;
private String status;
private int complete;
private int testsuiteid;
private int testprocedureid;
private String cdate;
private String revision;
private String environment;
private int planned_testcases;
private String start_date;
private String end_date;
private int completed_testcases;
private int failed;
private double percent;
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
private double value;
private int defects;
public int getDefects() {
return defects;
}
public void setDefects(int defects) {
this.defects = defects;
}
public double getPercent() {
return percent;
}
public void setPercent(double percent) {
this.percent = percent;
}
public int getFailed() {
return failed;
}
public void setFailed(int failed) {
this.failed = failed;
}
public String getEnvironment() {
return environment;
}
public void setEnvironment(String environment) {
this.environment = environment;
}
public int getComplete() {
return complete;
}
public void setComplete(int complete) {
this.complete = complete;
}
public int getPlanned_testcases() {
return planned_testcases;
}
public void setPlanned_testcases(int planned_testcases) {
this.planned_testcases = planned_testcases;
}
public int getCompleted_testcases() {
return completed_testcases;
}
public void setCompleted_testcases(int completed_testcases) {
this.completed_testcases = completed_testcases;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public int getTestsuiteid() {
return testsuiteid;
}
public void setTestsuiteid(int testsuiteid) {
this.testsuiteid = testsuiteid;
}
public int getTestprocedureid() {
return testprocedureid;
}
public void setTestprocedureid(int testprocedureid) {
this.testprocedureid = testprocedureid;
}
public String getCdate() {
return cdate;
}
public void setCdate(String cdate) {
this.cdate = cdate;
}
public String getRevision() {
return revision;
}
public void setRevision(String revision) {
this.revision = revision;
}
public String getStart_date() {
return start_date;
}
public void setStart_date(String start_date) {
this.start_date = start_date;
}
public String getEnd_date() {
return end_date;
}
public void setEnd_date(String end_date) {
this.end_date = end_date;
}
}
--------------------------------here comes my jsp-------------------------
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page language="java" import="com.osius.beans.TestCaseBean"%>
<%@ page language="java" import="com.osius.control.TestCase"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<input value =" Home" type="button" class="button" />
<input value ="Test Cases" type="button" class="button"/>
<input value ="Reports" type="button" class="button"/>
<input value ="Settings" type="button" class="button"/><br>
<br>
<br>
<br>
<head>
<title>Report1</title>
<LINK href="../css/web.css" rel="stylesheet" type="text/css">
</head>
<!-- Here creating object of the class -->
<% TestCase tc = new TestCase();
TestCaseBean tsb = new TestCaseBean();
ArrayList al = new ArrayList();
al= tc.test();
%>
<body>
<input value ="Plan New Test Cycle" type="button" class="btn"/> // these are buttons
<input value ="Start Test Cycle" type="button" size ="10" class="btn"/>
<input value ="Stop Test Cycle" type="button" size ="10" class="btn"/>
<!-- here starts my requirement -->
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#0AA4C5">
<tr align="right" bgcolor="#0AA4C5" >
<th align ="center"> Date</th>
<th> Description</th>
<th > %Completed</th>
<th> Status</th>
<th> Revision</th>
<th> Environment</th>
<th> Start Date</th>
<th> End Date</th>
<th> Planned Test Cases</th>
<th> Completed Test Cases</th>
<th> Failed</th>
<th> % Success</th>
<th> # Defects</th>
</tr>
//I have retrived the data and trying to dipaly it in a tabular format , where i am uisng <td <%...%>scriplet.
Instead of the below code i can use foreach tag i think can any one help me please!...
<% for(int i=0; i<al.size(); i++)
{
tsb =(TestCaseBean)al.get(i);%>
<tr>
<td width="500"><% out.println(tsb.getCdate()); %> </td>
<td width="500"><% out.println(tsb.getDescription()); %> </td>
<td width="200"><%out.println(tsb.getValue()); %> </td>
<td><% out.println(tsb.getStatus()); %> </td>
<td><% out.println(tsb.getRevision()); %> </td>
<td><% out.println(tsb.getEnvironment()); %> </td>
<td><% out.println(tsb.getStart_date()); %> </td>
<td><% out.println(tsb.getEnd_date()); %> </td>
<td><% out.println(tsb.getPlanned_testcases()); %> </td>
<td><% out.println(tsb.getCompleted_testcases()); %> </td>
<td><% out.println(tsb.getFailed());%></td>
<td><% out.println(tsb.getPercent());%></td>
<td><% out.println(tsb.getDefects());%></td>
<%} %>
</tr>
<% System.out.println(tsb.getPercent());%>
<% System.out.println(tsb.getValue());%>
</table>
</body>
</html>
thanks
Navin