Alguém pode me ajudar?
Não consigo ver o que pode estar errado nele entre as linhas 144 a 146.
public class CarritoServiceImpl
implements ICarritoService
{
ServletContext servletContext;
Connection con;
public CarritoServiceImpl()
{
servletContext = null;
con = null;
init();
}
public void setServletContext(ServletContext ctx)
{
servletContext = ctx;
}
public ServletContext getServletContext()
{
return servletContext;
}
public List getListaProducto()
{
List listaProducto = new LinkedList();
ResultSet result = null;
try
{
String query = "SELECT * FROM PRODUCTO";
Statement stmt = con.createStatement();
ProductoVO productoVO;
for(result = stmt.executeQuery(query); result.next(); listaProducto.add(productoVO))
{
int id = result.getInt("id");
String nombre = result.getString("nombre");
String descripcion = result.getString("descripcion");
String smallImageURL = result.getString("smallImageURL");
double basePrice = result.getDouble("basePrice");
productoVO = new ProductoVO(id, nombre, descripcion, basePrice, smallImageURL);
System.out.println(productoVO.toString());
}
}
catch(SQLException se)
{
System.err.println("Se ha producido un error de BD.");
System.err.println(se.getMessage());
}
return listaProducto;
}
public ProductoVO getDetalleProducto(String productoId)
{
ResultSet result = null;
ProductoVO productoVO = null;
try
{
String query = "SELECT * FROM PRODUCTO WHERE ID = " + productoId;
Statement stmt = con.createStatement();
result = stmt.executeQuery(query);
if(!result.next())
{
throw new SQLException();
}
int id = result.getInt("id");
String nombre = result.getString("nombre");
String descripcion = result.getString("descripcion");
String smallImageURL = result.getString("smallImageURL");
double basePrice = result.getDouble("basePrice");
productoVO = new ProductoVO(id, nombre, descripcion, basePrice, smallImageURL);
}
catch(SQLException se)
{
System.err.println("Se ha producido un error de BD.");
System.err.println(se.getMessage());
}
return productoVO;
}
public UserVO authenticate(String email, String password)
{
ResultSet result = null;
UserVO userVO = null;
try
{
String query = "SELECT * FROM USUARIO WHERE EMAIL = ? AND PASSWORD = ?";
PreparedStatement ps = con.prepareStatement(query);
ps.setString(1, email);
ps.setString(2, password);
result = ps.executeQuery();
if(result.next())
{
userVO = new UserVO();
userVO.setId(result.getInt("id"));
userVO.setFirstName(result.getString("FirstName"));
userVO.setLastName(result.getString("LastName"));
userVO.setEmailAddress(result.getString("Email"));
}
}
catch(SQLException se)
{
System.err.println("Se ha producido un error de BD.");
System.err.println(se.getMessage());
}
return userVO;
}
public void logout(String s)
{
}
public void destroy()
{
try
{
con.close();
}
catch(SQLException se)
{
System.err.println("Se ha producido un error al cerrar la conexi\363n de BD.");
System.err.println(se.getMessage());
}
}
private void init()
{
try
{
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/carrito", "root", "");
}
catch(SQLException se)
{
System.err.println("Se ha producido un error al abrir la conexi\363n de BD.");
System.err.println(se.getMessage());
}
catch(ClassNotFoundException s)
{
System.out.println("No se encuentra la clase " + s.toString());
}
}
}
