Erro tentando trazer dados de banco de dados

2 respostas
M

Estou tentando criar um código JSP que conecte com o MySQL e retorne os dados de uma tabela.

Para isso estou utilizando o NetBeans 5.0, fui em Library Manager e adicionei o JAR do Driver JDBC do MySQL (Não sei se este é o passo correto para adicionar um JAR de um Driver JDBC).

Estou utilizando o seguinte código:

<%
       Class.forName("com.mysql.jdbc.Driver");
       Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/db_noticia?user=root&password=TabX5Mfc8");
       
       Statement stm = conn.createStatement("SELECT DS_TITULO,DT_NOTICIA FROM CAD_NOTICIA");
       ResultSet rs = stm.execute();
       
       System.out.println("<table width='100%'>");
       System.out.println("<tr>");
       System.out.println("<td width='80%'>Título</td>");
       System.out.println("<td>Data</td>");
       System.out.println("</tr>");
       
       while(rs.next())
       {
           System.out.println("<tr>");
           
           String strTitulo = rs.getString("DS_TITULO");
           Date dtNoticia = rs.getDate("DT_NOTICIA");
           
           System.out.println("<td>" + strTitulo + "</td>");
           System.out.println("<td>" + dtNoticia.toString() + "</td>");
           
           System.out.println("</tr>");
       }
       
       System.out.println("</table>");
    %>

Onde está o erro????

2 Respostas

M

O erro que estou tendo é esse…

HTTP Status 500 -


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: 24 in the jsp file: /index.jsp
Generated servlet error:
C:\Documents and Settings\Juliano.netbeans\5.0\jakarta-tomcat-5.5.9_base\work\Catalina\localhost\DB1\org\apache\jsp\index_jsp.java:62: cannot find symbol
symbol : class Connection
location: class org.apache.jsp.index_jsp

An error occurred at line: 24 in the jsp file: /index.jsp
Generated servlet error:
Connection conn = DriverManager.getConnection(“jdbc:mysql://localhost/db_noticia?user=root&password=TabX5Mfc8”);
^

An error occurred at line: 24 in the jsp file: /index.jsp
Generated servlet error:
C:\Documents and Settings\Juliano.netbeans\5.0\jakarta-tomcat-5.5.9_base\work\Catalina\localhost\DB1\org\apache\jsp\index_jsp.java:62: cannot find symbol
symbol : variable DriverManager
location: class org.apache.jsp.index_jsp

An error occurred at line: 24 in the jsp file: /index.jsp
Generated servlet error:
Connection conn = DriverManager.getConnection(“jdbc:mysql://localhost/db_noticia?user=root&password=TabX5Mfc8”);
^

An error occurred at line: 24 in the jsp file: /index.jsp
Generated servlet error:
C:\Documents and Settings\Juliano.netbeans\5.0\jakarta-tomcat-5.5.9_base\work\Catalina\localhost\DB1\org\apache\jsp\index_jsp.java:64: cannot find symbol
symbol : class Statement
location: class org.apache.jsp.index_jsp
Statement stm = conn.createStatement(“SELECT DS_TITULO,DT_NOTICIA FROM CAD_NOTICIA”);
^

An error occurred at line: 24 in the jsp file: /index.jsp
Generated servlet error:
C:\Documents and Settings\Juliano.netbeans\5.0\jakarta-tomcat-5.5.9_base\work\Catalina\localhost\DB1\org\apache\jsp\index_jsp.java:65: cannot find symbol
symbol : class ResultSet
location: class org.apache.jsp.index_jsp
ResultSet rs = stm.execute();
^

An error occurred at line: 24 in the jsp file: /index.jsp
Generated servlet error:
C:\Documents and Settings\Juliano.netbeans\5.0\jakarta-tomcat-5.5.9_base\work\Catalina\localhost\DB1\org\apache\jsp\index_jsp.java:78: cannot find symbol
symbol : class Date
location: class org.apache.jsp.index_jsp
Date dtNoticia = rs.getDate(“DT_NOTICIA”);
^
5 errors

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.AntCompiler.generateClass(AntCompiler.java:246)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.


Apache Tomcat/5.5.9

thiago.correa

tente dar import nas classes que você está usando!

Criado 26 de março de 2006
Ultima resposta 26 de mar. de 2006
Respostas 2
Participantes 2