<%@ page language="java" import="java.sql.*" %>
<html>
<head><title></title>
</head>
<body>
<%
String setor = (String) request.getParameter("grupo");
//String setor3 = (String) request.getParameter("grupo");
String url = "jdbc:mysql://localhost/shelter";
String usuario = "root";
String senha = "1272";
Connection conn = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, usuario, senha);
}
catch(SQLException ex){
out.println("SQLException: " + ex.getMessage() + "<br>");
out.println("SQLState: " + ex.getSQLState() + "<br>");
out.println("VendorError: " + ex.getErrorCode() + "<br>");
}
catch(Exception e){
out.println("Problemas ao tentar conectar com o banco de dados");
}
// conn é a conexão com o banco de dados
int limit = 15; // quantidade de resultados por página
// obtém a quantidade de registros
PreparedStatement pstmt = conn.prepareStatement
("select count(*) as c From ramal R where R.grupo = '"+ setor +"' ");
//("select count(*) as c From tb_ligacoes L, ramal R where R.ramal = L.ramal And R.grupo = ativos ");
// ("SELECT COUNT(*) AS c FROM TB_LIGACOES where ramal = 1037");
ResultSet rs = pstmt.executeQuery();
rs.next();
int total_rows = Integer.parseInt(rs.getString("c"));
String pagina = request.getParameter("pagina"); // página atual
if(pagina == null){
pagina = "1";
}
int limitValue = (Integer.parseInt(pagina) * limit) - limit;
PreparedStatement pstmt2 = conn.prepareStatement
("select R.ramal, count(recebida) as recebidas, count(n_discado) as efetuadas From tb_ligacoes L, ramal R " +
"where R.ramal = L.ramal And R.grupo = '"+ setor +"' Group by R.ramal LIMIT " + limitValue + ", " + limit );
// ("SELECT * FROM TB_LIGACOES where ramal = 1037 LIMIT " + limitValue + ", " + limit);
ResultSet rs2 = pstmt2.executeQuery();
%>
<table border="0">
<tr><th>Ramal</th><th>Ligações efetuadas</th><th>Ligações recebidas</th></tr>
<%
while(rs2.next()) {
out.print("<tr>\n<td>" + rs2.getString("RAMAL") + "</td>");
out.print("<td>" + rs2.getString("efetuadas") + "</td>");
out.print("<td>" + rs2.getString("recebidas") + "</td>");
out.print("</tr></td>\n</tr>");
//int id = rs2.getInt("RAMAL");
//out.println("ID: " + id + "<br>");
//String nome = rs2.getString("N_DISCADO");
//out.println("NOME: " + nome + "<br>");
//int idade = rs2.getInt("OPERADORA");
//out.println("IDADE: " + idade + "<br><br>");
}
%>
</tr>
</table>
<%
int anterior;
if(Integer.parseInt(pagina) != 1){
anterior = Integer.parseInt(pagina) - 1;
out.println("<a href=?pagina=" + anterior + ">" + limit + " Anteriores</a>");
}
else
out.println(limit + " Anteriores ");
int numOfPages = total_rows / limit;
int i;
for(i = 1; i <= numOfPages; i++){
if(i == Integer.parseInt(pagina)){
out.println("<b>" + i + "</b> ");
}
else{
out.println("<a href=?pagina=" + i + ">" + i + "</a> ");
}
}
if((total_rows % limit) != 0){
if(i == Integer.parseInt(pagina)){
out.println(i + " ");
}
else{
out.println("<a href=?pagina=" + i + ">" + i + "</a> ");
}
}
int proxima;
if((total_rows - (limit * Integer.parseInt(pagina))) > 0){
proxima = Integer.parseInt(pagina) + 1;
out.println("<a href=?pagina=" + proxima + ">Próximos " + limit + "</a>");
}
else
out.println("Próximos " + limit);
%>
</body>
</html>
qual o drama:
Quando click para exibir a proxima quantidade de registro, a tabela me mostra vazio.
Obs.: A tabela so me lista os 15 primeiros arquivos.
Alguem poderia me ajudar?
Abraços,
