Salve galera
Seguinte, estou começando a estudar a parte de Web com Java, estou vendo a apostila FJ21 da Caelum aqui: http://www.caelum.com.br/download/caelum-java-web-fj21.pdf
Negocio é que quero criar um DAO para um SELECT no meu BD e estou apanhando um pouco sobre isso.
Estou tentando assim.
pacotes(packages):
src
br.com.residencialthobiaslandim.db
br.com.residencialthobiaslandim.dao
br.com.residencialthobiaslandim.servlet
br.com.residencialthobiaslandim.pojo
//Conexao
package br.com.residencialthobiaslandim.db;
public class Conexao {
public static Connection getConnection() throws SQLException{
try {
Class.forName("com.mysql.jdbc.Driver");
return DriverManager.getConnection("jdbc:mysql://xxx.xxx.xxx.xxx/myDB?user=user&password=mypass");
} catch (ClassNotFoundException e) {
throw new SQLException();
}
}
}
// Usuarios POJO
package br.com.residencialthobiaslandim.pojo;
public class Usuarios {
private Long id;
private String login;
private String nome;
//set e get
}
// DAO de Usuarios
package br.com.residencialthobiaslandim.dao;
public class UsuariosDAO {
private Connection con;
public UsuariosDAO(){
try {
this.con = Conexao.getConnection();
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println(e.getLocalizedMessage());
}
}
public List<Usuarios> getUsuarios(){
List<Usuarios> lista = new ArrayList<Usuarios>();
try {
PreparedStatement stm = this.con.prepareStatement("SELECT * FROM yusuarios");
ResultSet rs = stm.executeQuery();
while(rs.next()){
Usuarios u = new Usuarios();
u.setId(rs.getLong("id"));
u.setLogin(rs.getString("login"));
u.setNome(rs.getString("nome"));
lista.add(u);
}
rs.close();
stm.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println(e.getLocalizedMessage());
}
return lista;
}
}
//ExibeUsuarios.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>.: Usuários :.</title>
</head>
<body>
<jsp:useBean id="dao" class="br.com.residencialthobiaslandim.dao.UsuariosDAO"/>
<c:forEach var="u" items="${dao.lista}">
${u.nome}
</c:forEach>
</body>
</html>
O erro esta na imagem em anexo no post.
