Guest User

Untitled

a guest
Jul 16th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. <%@ page import="java.io.*, java.util.*, java.net.*, java.sql.*"%>
  2. <%@ include file="conexion.jsp"%>
  3. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >>
  4. <html>
  5. <head><title>Listado de Productos</title></head>
  6. <body>
  7.  
  8. Los productos que el usuario ha comprado son:
  9. <p></p>
  10.  
  11. <center>
  12. <%
  13. out.println("<table border=1>");
  14. out.println("<tr><th>Id del producto</th><th>Nombre</th><th>Descrici&oacute;n</th><th>Categoria</th><th>Usuario</th><th>Precio</th></tr>");
  15.  
  16. try{
  17. //Aqui se abre la conexion
  18. String conexion = ("jdbc:mysql://localhost/BDIS user="+usuarioMysql()+"&password="+passwordMysql());
  19. Class.forName("com.mysql.jdbc.Driver").newInstance();
  20. //Connection con = DriverManager.getConnection("jdbc:mysql://localhost/BDIS", "root","mellon");
  21. Connection con = DriverManager.getConnection(conexion);
  22.  
  23. Statement st = con.createStatement();
  24. //Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  25.  
  26. //NOTA: Acá conviene que ponga "Where NOM_USU= 'usuario'"
  27. ResultSet res = st.executeQuery("select * from ProductoBD;");
  28.  
  29. //Acá irían los datos pero no los despliega no sé porque
  30. while(res.next()){
  31. out.println("<tr><td>"+res.getInt(1)+"</td><td>"+res.getString(2)+"</td><td>"+res.getString(3)+"</td><td>"+res.getInt(4)+"</td><td>"+res.getString(5)+"</td><td>"+res.getDouble(5)+"</td></tr>");
  32. }
  33. out.println("</table>");
  34.  
  35. }
  36. catch(ClassNotFoundException cnfe){
  37. cnfe.printStackTrace();
  38. }
  39. catch(SQLException sqle){
  40. sqle.printStackTrace();
  41. }
  42. catch(Exception e){
  43. e.printStackTrace();
  44. }
  45. %>
  46. </center></body>
  47. <html>
Add Comment
Please, Sign In to add comment