Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Juliano.net

Erro em conexão com MySQL em JSP

Recommended Posts

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????

Compartilhar este post


Link para o post
Compartilhar em outros sites

HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to load class for JSP org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:591) org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:137) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305) 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)root cause java.lang.ClassNotFoundException: org.apache.jsp.index_jsp java.net.URLClassLoader$1.run(URLClassLoader.java:200) java.security.AccessController.doPrivileged(Native Method) java.net.URLClassLoader.findClass(URLClassLoader.java:188) org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:158) org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:71) org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:589) org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:137) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305) 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

Compartilhar este post


Link para o post
Compartilhar em outros sites

O exemplo que vem no NetBeans roda normalmente....só o código que criei que não....pra poder usar o Driver do MySQL tenho que colocá-lo no diretório C:\Program Files\Java\jre1.5.0_06\lib\ext ou em algum diretório do Tomcat???

Compartilhar este post


Link para o post
Compartilhar em outros sites

Agora o erro é outro...HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 24 in the jsp file: /index.jspGenerated 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 symbolsymbol : class Connectionlocation: class org.apache.jsp.index_jspAn error occurred at line: 24 in the jsp file: /index.jspGenerated 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.jspGenerated 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 symbolsymbol : variable DriverManagerlocation: class org.apache.jsp.index_jspAn error occurred at line: 24 in the jsp file: /index.jspGenerated 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.jspGenerated 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 symbolsymbol : class Statementlocation: 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.jspGenerated 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 symbolsymbol : class ResultSetlocation: class org.apache.jsp.index_jsp ResultSet rs = stm.execute(); ^An error occurred at line: 24 in the jsp file: /index.jspGenerated 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 symbolsymbol : class Datelocation: 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

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.