Página JSP

Me ajudem a descobrir porque essa página JSP não está funcionando.
Na linha:

<td width=“84%”><input type=“text” name=“tfcodContrato” size=“20” value="<%= codigo %>"></td>

NÃO APARECE O VALOR DA VARIÁVEL CODIGO!!!

Segue abaixo:

[code]<%@ page import="java.sql.*" %>
<%@ page import="java.lang.String" %>
<html>
<body>
<%
Connection con = null;
Statement st = null;

try&#123;
   Class.forName&#40;&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;&#41;;
&#125;
catch &#40;Exception e&#41;&#123;
      System.out.println&#40;&quot;Erro&quot; + e&#41;;
&#125;
try&#123;
con = DriverManager.getConnection&#40;&quot;jdbc&#58;odbc&#58;Controle_Contratos&quot;,&quot;&quot;,&quot;&quot;&#41;;
&#125;
catch&#40;SQLException k&#41;&#123;
      System.out.println&#40;&quot;Erro&quot; + k&#41;;
&#125;
try&#123;
st = con.createStatement&#40;&#41;;
    
    int codigo;

    ResultSet rs = st.executeQuery&#40;&quot;select max&#40;codContrato&#41;as codigo from tbContratos&quot;&#41;;

    codigo = rs.getInt&#40;&quot;codigo&quot;&#41;+1;

        st.close&#40;&#41;;
        con.close&#40;&#41;;
    
&#125;catch&#40;Exception s&#41;&#123;

System.out.println&#40;&quot;Erro&#58;&quot; + s&#41;;
&#125;
finally&#123;
  try&#123;
  	if&#40;st != null&#41;
  	   st.close&#40;&#41;;
  	 
  	 &#125; catch &#40;SQLException a&#41;&#123;&#125;
  	 try&#123;
  	 	if&#40;con!= null&#41;
  	 	   con.close&#40;&#41;;
&#125;catch&#40;SQLException a&#41;&#123;&#125;

}%>

<form method="POST" action="incluirContrato.jsp">
<table>
<tr>
<td width="16%">Código Contrato:</td>
<td width="84%"><input type="text" name="tfcodContrato" size="20" value="<%= codigo %>"></td>
</tr>
<tr>
<td width="16%">Número Contrato:</td>
<td width="84%"><input type="text" name="tfNumContrato" size="20"></td>
</tr>
<tr>
<td width="16%">Fornecedor:</td>
<td width="84%"><input type="text" name="tfFornecedor" size="20"></td>
</tr>
<tr>
<td>Assunto</td>
<td><input type="text" name="tfAssunto" size="20"></td>
</tr>
</table>
<p><input type="submit" value="Enviar" name="btEnviar"><input type="reset" value="Limpar" name="btLimpar"></p>
</form>
</body>
</html>

[/code]Obrigada

[color="#009900"]Alterado para conter o BBCode - CODE[/color]

Oi

Thais, bom, o mais provável é o seu select não estar trazendo resultado mesmo…

Quando vc roda isso direto no banco

  select max&#40;codContrato&#41;as codigo from tbContratos

Vem alguma coisa?

T+

Thais, como o jeve disse verifique se a chave primaria da sua tabela é realmente codContrato

teste seu sql em algum cliente que tenha o seu DB…

:wink:

Tente fazer assim:

value=&quot;&lt;%out.print&#40;codigo&#41; %&gt;&quot;&gt;

Ate mais!!!