Pessoal, fiz uma classe JDBCConexao.java e uma Dados.java… mas qndo vou acessar pelo meu jsp…esta dando o seguinte erro…
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 22 in the jsp file: /teste.jsp
Generated servlet error:
D:\work\site\work\org\apache\jsp\teste_jsp.java:69: cannot resolve symbol
symbol : method consultarCategoria ()
location: class org.apache.jsp.teste_jsp
ResultSet rs = consultarCategoria();
^
1 error
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
Os meus arquivos sao os seguintes…
JDBCConexao.java
package com.site;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class JDBCConexao {
private String driver;
private String url;
private String username;
private String password;
public Connection getConexao() {
Connection con = null;
try {
Class.forName( this.getDriver() );
con = DriverManager.getConnection( this.getUrl(),
this.getUsername(), this.getPassword() );
return con;
} catch ( ClassNotFoundException cnfe ) {
} catch ( SQLException se ) {
}
return con;
} // end getConexao
public void setConexao( String driver, String url,
String username, String password ) {
this.setDriver( driver );
this.setUrl( url );
this.setUsername( username );
this.setPassword( password );
} // end setConexao
public void fecharConexao( Connection con, PreparedStatement ps,
ResultSet rs ) {
try {
if ( rs != null ) {
rs.close();
}
fecharConexao( con, ps );
} catch ( Exception e ) {
}
} // end fecharConexao
public void fecharConexao( Connection con, PreparedStatement ps ) {
try {
if ( ps != null ) {
ps.close();
}
if ( con != null ) {
con.close();
}
} catch ( Exception e ) {
}
} // end fecharConexao
private String getDriver() {
return driver;
} // end getDriver
private void setDriver(String driver) {
this.driver = driver;
} // end setDriver
private String getPassword() {
return password;
} // end getPassword
private void setPassword(String password) {
this.password = password;
} // end setPassword
private String getUrl() {
return url;
} // end getUrl
private void setUrl(String url) {
this.url = url;
} // end setUrl
private String getUsername() {
return username;
} // end getUsername
private void setUsername(String username) {
this.username = username;
} // end setUsername
} // end class
Dados.java
package com.site;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Dados {
// atributos da tabela categoria
private int codCat;
private String nomeCat;
// atributos de conexão com o banco
private String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
private String url = "jdbc:odbc:Banco";
private String username = "";
private String password = "";
public Connection getConexao() {
JDBCConexao conexao = new JDBCConexao();
conexao.setConexao( driver, url, username, password );
Connection con = conexao.getConexao();
return con;
} // end getConexao
public void fecharConexao( Connection con, PreparedStatement ps,
ResultSet rs ) {
JDBCConexao conexao = new JDBCConexao();
conexao.fecharConexao( con, ps, rs );
} // end fecharConexao
public void fecharConexao( Connection con, PreparedStatement ps ) {
JDBCConexao conexao = new JDBCConexao();
conexao.fecharConexao( con, ps );
} // end fecharConexao
/**
* @return Returns the codCat.
*/
public int getCodCat() {
return codCat;
}
/**
* @param codCat The codCat to set.
*/
public void setCodCat(int codCat) {
this.codCat = codCat;
}
/**
* @return Returns the nomeCat.
*/
public String getNomeCat() {
return nomeCat;
}
/**
* @param nomeCat The nomeCat to set.
*/
public void setNomeCat(String nomeCat) {
this.nomeCat = nomeCat;
}
public ResultSet consultarCategoria() {
Connection con = getConexao();
PreparedStatement ps = null;
ResultSet rs = null;
String comandoConsultar = "";
try {
comandoConsultar = "select * from categorias";
ps = con.prepareStatement( comandoConsultar );
rs = ps.executeQuery();
return rs;
} catch ( SQLException se ) {
}
return rs;
} // end consultarCategoria
}
index.jsp
<%@ page import="java.sql.ResultSet" %>
<%@ page import="com.site.Dados" %>
<%!
public int getProximo() {
Dados dados = new Dados();
int codigo = dados.getProximo();
return codigo;
}
public ResultSet consultarVeiculo() {
Dados dados = new Dados();
ResultSet rs = dados.consultarCategoria();
return rs;
}
%>
<% ResultSet rs = consultarCategoria(); %>
<hr>
<table>
<tr>
<td colspan="5" align="center"><h4>Categorias Cadastradas</h4></td>
</tr>
<tr class="cinza">
<td width="50">Código</td>
<td width="80">Nome da Categoria</td>
</tr>
<%
while ( rs.next() ) {
%>
<tr>
<td><%= rs.getString( "cod_cat" ) %></td>
<td><%= rs.getString( "nome_cat" ) %></td>
</tr>
<%
}
%>
</table>
O que poderá estar me causando esse erro?