The code i have is:
(RECORDSARRAY)
public class ArrayRecords{
private int id;
private String service;
private String technician;
private String state;
private String startDate;
private String endDate;
private String startTime;
private String endTime;
private String description;
private String priority;
GETTERS AND SETTER ; AND THE CONSTRUCTORS USING FIELDS.
(ConnectionDB)
public ArrayList <ArrayRecords> showList(){
ArrayList<ArrayRecords> recordList= null;
ArrayRecords arrayRecords=null;
if (connection != null) {
try{
recordList= new ArrayList<ArrayRecords>();
Statement statement = connection.createStatement();
String query=String.format("SELECT Registos.id,nomeServico,nomeTecnico,estado,dataInicio,dataFim,horaInicio,horaFim,descricao,prioridade FROM Servicos,Tecnicos,Estados,Registos WHERE servicos_id=Servicos.id and tecnicos_id=Tecnicos.id and estados_id=Estados.id");
ResultSet rs = statement.executeQuery(query);
while (rs.next()) {
arrayRecords= new ArrayRecords (rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8),rs.getString(9),rs.getString(10));
recordList.add(arrayRecords);
}
}catch(SQLException ex){
ex.printStackTrace();
}
}
return recordList;
}
(SERVLET)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ConnectionDB connectionDB = new connectionDB();
ArrayList<ArrayRecords> recordList;
recordList= connectionDB .showList();
request.setAttribute("recordList",recordList);
RequestDispatcher view = request.getRequestDispatcher("recordList.jsp");
vista.forward(request, response);
}
(JSP)
<%
ArrayList<ArrayRecords> recordList= (ArrayList<ArrayRecords>) request.getAttribute("recordList");
if (recordList.size() == 0) {
out.println("<h2>No Records</h2>");
%><%
} else {%><%
out.println("<table id=\"myTable\" border=3 width=\"1100\"height=\"1\">");
out.println("<thead>");
out.println("<tr>");
out.println("<center><td>Estado</td><td>Data Início</td><td>Hora Início</td><td>Técnico</td><td>Serviço</td><td>Descricao</td><td>Data Fim</td><td>Hora Fim</td></center>");
out.println("</tr>");
out.println("</thead>");
out.println("<tbody>");
for (ArrayRecords i : recordList) {
if(i.getState().equals("Pendente")){
out.println("<tr class=\"pendente\">");
out.println("<td>");
out.println(String.format("<center><a href=\"Detail?details="+i.getId()+"\"><span id=\"cor\" style=\"color: red ;\">"+i.getState()+"</span></a></center>"));
}else if(i.getState().equals("Concluído")){
out.println("<tr class=\"concluido\">");
out.println("<td>");
out.println(String.format("<center><a href=\"Detail?details="+i.getId()+"\"><span id=\"cor\" style=\"color: green ;\">"+i.getState()+"</span></a></center>"));
}else if(i.getState().equals("Validado")){
out.println("<tr class=\"validado\">");
out.println("<td>");
out.println(String.format("<center><a href=\"Detail?details="+i.getId()+"\"><span id=\"cor\" style=\"color: blue ;\">"+i.getState()+"</span></a></center>"));
}
out.println("</td>");
out.println("<td>");
out.println(String.format("<center>"+i.getStartDate()+"</center>"));
out.println("</td>");
out.println("<td>");
out.println(String.format("<center>"+i.getStartTime()+"</center>"));
out.println("</td>");
out.println("<td>");
out.println(String.format("<center>"+i.getTechnician()+"</center>"));
out.println("</td>");
out.println("<td>");
out.println(String.format("<center>"+i.getService()+"</center>"));
out.println("</td>");
out.println("<td>");
String description = i.getDescription();
if (description !=null && description .length()> 60){
out.println("</span>");
description =description .substring(0,40);
out.println("<center><span class=\"dropt\" title=\"\">"+descricao+"...</center>");
out.println("<span style=\"color: black ;\">"+i.getDescricao()+"</span>");
}else if(description ==null){
description ="No description";
out.println(String.format("<center>"+description+"</center>"));
}else if(description.isEmpty()){
description ="No description";
out.println(String.format("<center>"+description+"</center>"));
}else{
out.println(String.format("<center>"+i.getDescription()+"</center>"));
}
out.println("</td>");
out.println("<td>");
out.println(String.format("<center>"+i.getEndDate()+"</center>"));
out.println("</td>");
out.println("<td>");
out.println(String.format("<center>"+i.getEndTime()+"</center>"));
out.println("</td>");
out.println("</tr>");
}
out.println("</tbody>");
out.println("</table>");
}
//}
%>
The image shows the table, which is being sucessfully created with this code i posted here. but i wanted to show only 20 of the records, then have a next button to give the next 20 records. bcuz if the SQL table get's more crowded it will grow and it will be painfull to the user to scroll down...
I hope i explained myself.
And i hope for some help plz...