Bom dia Galera !!
Estou seguindo os exemplos de um livro e estou com 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: Exception in JSP: /ListaCidades.jsp:35
32: }
33:
34: try{
35: stmt = connection.createStatement();
36: }catch(SQLException e){
37: e.printStackTrace();
38: }
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NullPointerException
org.apache.jsp.ListaCidades_jsp._jspService(ListaCidades_jsp.java:76)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.25 logs.
Apache Tomcat/5.5.25
<%@ page language=“java” contentType="text/html; charset=ISO-8859-1"
pageEncoding=“ISO-8859-1”%>
Connection connection = null;
String user = "root";
String password = "root";
String url = "jdbc:mysql://localhost:3306/aula";
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (InstantiationException ae) {
ae.printStackTrace();
} catch (IllegalAccessError be) {
be.printStackTrace();
} catch (ClassNotFoundException ce) {
ce.printStackTrace();
}
try {
connection = DriverManager.getConnection(url, user, password);
}catch(SQLException e){
e.printStackTrace();
}
try{
stmt = connection.createStatement();
}catch(SQLException e){
e.printStackTrace();
}
try{
rs = stmt.executeQuery("select * from cidade order by nome");
}catch(SQLException e){
e.printStackTrace();
}
out.println("<h1> Lista de Cidades </h1><h2>");
while(rs.next()){
out.println(rs.getString("nome")+"<br");
}
out.println("</h2>");
%>
Desde já agradeço .