Erro em página JSP

2 respostas
J
página index.jsp
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@include file="WEB-INF/jspf/banco.jspf"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Controle de Patrimonio</title>
    </head>
    <body>

<table width="400" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td>Código</td>
    <td>Descrição</td>
    <td>Modelo</td>
    <td>Acessórios</td>
  </tr>
 <%
 ResultSet  res = null;
 res = stm.executeQuery(
  "SELECT *  FROM tbl_itens");
String cod;
cod = res.getString("id");
 boolean liga = true; 
while (res.next()) {%>
  <tr bgcolor="<%=  ((liga = !liga)?"#EBEBEB":"")  %>">
    <td><%= res.getString("codigo")%></td>
    <td><%= res.getString("descricao")%></td>
    <td><%= res.getString("modelo")%></td>
  </tr>
  <% } 
res.close();%>
</table>
    
    </body>
</html>
página de erro
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page isErrorPage="true"%>
<%@page import="java.util.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Erro no Sistema</title>
        <link href="css.css" rel="stylesheet" type="text/css" /
    </head>
    <body>

    <h1>Problema no Sistema</h1>
    <p><b>Favor Informar ao analista do Sistema o seguinte erro:</b></p>
    <%= exception.getMessage()%>    
    
    </body>
</html>
página banco.jspf
<%@page language="java" import="java.sql.*"%>
<%@ page errorPage="erro.jsp"%>
<link href="css.css" rel="stylesheet" type="text/css" /
<%
response.setDateHeader("Expires", 0);
response.setHeader("Pragma", "no-cache");
if (request.getProtocol().equals("HTTP/1.1"))
    response.setHeader("Cache-Control", "no-cache");
%>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(
  "jdbc:mysql://localhost:3306/patrimonio","root","root");
Statement stm = con.createStatement();
%>
Erro gerado pelo sistema:
Problema no Sistema
Favor Informar ao analista do Sistema o seguinte erro:

Before start of result set

2 Respostas

J

Faltou mover o cursor do ResultSet:

ResultSet res = null; res = stm.executeQuery("SELECT * FROM tbl_itens"); res.next(); String cod; cod = res.getString("id");

J

certinho Jair, vlw…

Criado 24 de outubro de 2006
Ultima resposta 24 de out. de 2006
Respostas 2
Participantes 2