A tabela não exibe os dados, mas estou a 4 horas revisando e não acho nada que esteja incorreto
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dao;
import Connection.Conexao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import model.Paises;
/**
*
* @author pedro
*/
public class AmericaSulDao {
private Connection connection;
public AmericaSulDao() {
connection = Conexao.getConnection();
}
public void addPaises(Paises americaSul) {
Connection con = Conexao.getConnection();
PreparedStatement stmt = null;
try {
stmt = con.prepareStatement("INSERT INTO paises (nome_pais, continente_id_continente, id_paises)VALUES(?,?,?)");
stmt.setString(1, americaSul.getNomePais());
stmt.executeUpdate();
} catch (SQLException ex) {
System.out.println(ex);
}
}
public void deleteAmericaSul(int IdAmericaSul) {
String sqlString = "update continente set nome_pais=?, continente_id_continente=?, id_paises=? where cd_paises=?";
PreparedStatement stm = null;
try {
stm = connection.prepareStatement("delete from where id_paises=?");
// Parameters start with 1
stm.setInt(1, IdAmericaSul);
stm.executeUpdate();
stm.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void updateAmericaSul(Paises americaSul) {
PreparedStatement stm = null;
try {
stm = connection.prepareStatement("update continente set nome_pais=?, continente_id_continente=?, id_paises=? where cd_paises=?");
stm.setString(1, americaSul.getNomePais());
stm.setInt(2, americaSul.getContinente_id_continente());
stm.setInt(3, americaSul.getIdPaises());
stm.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
public List<Paises> getAllAmericaSul() {
List<Paises> listaAmericaSul = new ArrayList<Paises>();
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select nome_pais from paises, continente where nome_continente = America do Sul");
while (rs.next()) {
Paises americaSul = new Paises();
americaSul.setNomePais(rs.getString("nome_pais"));
americaSul.setIdContinente(rs.getInt("continente_id_continente"));
americaSul.setIdPaises(rs.getInt("id_paises"));
listaAmericaSul.add(americaSul);
}
} catch (SQLException e) {
e.printStackTrace();
}
return listaAmericaSul;
}
public Paises getAmericaSulByID(int idAmericaSul) {
Paises americaSul = new Paises();
try {
PreparedStatement preparedStatement = connection.prepareStatement("select nome_pais from paises, continente where nome_continente = America do Sul and id_paises=?");
preparedStatement.setInt(1, idAmericaSul);
ResultSet rs = preparedStatement.executeQuery();
if (rs.next()) {
americaSul.setIdContinente(rs.getInt("continente_id_continente"));
americaSul.setIdPaises(rs.getInt("id_paises"));
americaSul.setNomePais(rs.getString("nm_paises"));
}
} catch (SQLException e) {
e.printStackTrace();
}
return americaSul;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package controller;
import dao.AmericaSulDao;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Continentes;
import model.Paises;
/**
*
* @author pedro
*/
@WebServlet(name = "AmericaSul", urlPatterns = {"/AmericaSulController"})
public class AmericaSulController extends HttpServlet {
private static final long serialVersionUID = 1L;
private static String INSERT_OR_EDIT = "/telaAmericaSul.jsp";
private static String LIST_CONT = "/telaAmericaSul.jsp";
private AmericaSulDao dao;
public AmericaSulController() {
super();
dao = new AmericaSulDao();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String forward="";
String action = request.getParameter("action");
if (action.equalsIgnoreCase("delete")){
int IdAmericaSul = Integer.parseInt(request.getParameter("IdAmericaSul"));
dao.deleteAmericaSul(IdAmericaSul);
forward = LIST_CONT;
request.setAttribute("americaSul", dao.getAllAmericaSul());
}
else if (action.equalsIgnoreCase("edit")){
forward = INSERT_OR_EDIT;
int IdAmericaSul = Integer.parseInt(request.getParameter("IdAmericaSul"));
Paises americaSul = dao.getAmericaSulByID(IdAmericaSul);
request.setAttribute("americaSul", americaSul);
}
else if (action.equalsIgnoreCase("listaAmericaSul")){
forward = LIST_CONT;
request.setAttribute("americaSul", dao.getAllAmericaSul());
}
else {
forward = INSERT_OR_EDIT;
}
RequestDispatcher view = request.getRequestDispatcher(forward);
view.forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Paises americaSul = new Paises();
americaSul.setIdContinente(Integer.parseInt(request.getParameter("id_paises")));
americaSul.setNomePais(request.getParameter("nome_pais"));
americaSul.setIdContinente(Integer.parseInt(request.getParameter("continente_id_continente")));
String IdAmericaSul = request.getParameter("IdAmericaSul");
if(IdAmericaSul == null || IdAmericaSul.isEmpty())
{
dao.addPaises(americaSul);
}
else
{
americaSul.setIdPaises(Integer.parseInt(IdAmericaSul));
dao.updateAmericaSul(americaSul);
}
RequestDispatcher view = request.getRequestDispatcher(LIST_CONT);
request.setAttribute("IdAmericaSul", dao.getAllAmericaSul());
view.forward(request, response);
}
}