For the last time. What's wrong in these code ? please let your opnion.

I can'nt get the data from the list in <c:forEach> tag, are you able to see the possible error?though the jsp page is returned, it is all in blank.
the codes are these:
-my conecction and where i get my list
package teste;
public class Data {
    Connection con;
    Detalhes detalhes;
    int codigo;
    ArrayList  list;
    public Data()throws Exception {       
        try {
            Class.forName("org.gjt.mm.mysql.Driver");
            con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/Loja?user=root&password=131283");            
        } catch (Exception ex) {
            throw new Exception(" Database not found!!" +
                ex.getMessage());
    public void remove() {
        try {
            con.close();
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
    public void setCodigo(int codigo){
        this.codigo = codigo;
    public Detalhes getDetalhes(){
        try {
            String selectStatement = "select * from produto where codigo="+codigo;
            PreparedStatement prepStmt = con.prepareStatement(selectStatement);
            ResultSet rs = prepStmt.executeQuery();
            while(rs.next())
                 detalhes = new Detalhes(rs.getString(1), rs.getString(2), rs.getDouble(3), rs.getInt(4));          
            prepStmt.close();
        }catch(Exception e){
       return detalhes;
    public ArrayList getList(){
        try {
            list = new ArrayList();
            String selectStatement = "select * from produto";
            PreparedStatement prepStmt = con.prepareStatement(selectStatement);
            ResultSet rs = prepStmt.executeQuery();
            while(rs.next()){
                 detalhes = new Detalhes(rs.getString(1), rs.getString(2), rs.getDouble(3), rs.getInt(4));          
                 list.add(detalhes);
            prepStmt.close();
            Collections.sort(list);
        }catch(Exception e){
            System.out.println(e.getMessage());
        return list;
}    - the object where i store and show the data through the methods
package teste;
public class Detalhes {
    private String titulo;
    private String autor;
    private Double preco;
    private int codigo;
    public Detalhes(String titulo, String autor, Double preco, int codigo) {
        this.titulo = titulo;
        this.autor = autor;
        this.preco = preco;
        this.codigo = codigo;       
    public String getTitulo(){
        return titulo;
    public String getAutor(){
        return autor;
    public Double getPreco(){
        return preco;
    public int getCodigo(){
        return codigo;
}-my inicial context class
package teste;
import javax.servlet.*;
public final class ContextPage implements ServletContextListener {
    private ServletContext context = null;
    NewClass bookDB;
    public void contextInitialized(ServletContextEvent event) {
        context = event.getServletContext();
        try {
            bookDB = new NewClass();
            context.setAttribute("bookDB", bookDB);
        } catch (Exception ex) {
            System.out.println("Couldn't create bookstore database bean: " +
                ex.getMessage());
    public void contextDestroyed(ServletContextEvent event) {
        context = event.getServletContext();
        NewClass dados = (NewClass) context.getAttribute("bookDB");
        if (dados != null) {
            dados.remove();
        context.removeAttribute("bookDB");              
}- my jsp page
<p><b><h1>Resultado:</h1></b></p><br>
<jsp:useBean id="dataSource" class="teste.Data" scope="page" >
       <jsp:setProperty name="dataSource" property="codigo" value="${param.theCode}"/>          
</jsp:useBean>
<c:forEach var="book" items="${dataSource.list}">
    <p><b><h1><font color="red">${book.titulo}<h1></b></p>        
    <p><b><h1><font color="red">${book.autor}<h1></b></p>        
    <p><b><h1><font color="red">${book.preco}<h1></b></p>        
    <p><b><h1><font color="red">${book.codigo}<h1></b></p>        
</c:forEach>
<c:out value=${bookList}/>

First of all: Don't try to force a response by using a subject "For the last time ..."
Independent of your original problem
There are a lot of things which are not correct in your code.
// i would never use the user root to access a database :-(
con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/Loja?user=root&password=131283");
public Detalhes getDetalhes(){
        PreparedStatement prepStmt = null;
        ResultSet rs = null;
        try {
            // use place holders when working with prepared statements
            //  String selectStatement = "select * from produto where codigo="+codigo;
             String selectStatement = "select * from produto where codigo= ?" ;
            PreparedStatement prepStmt = con.prepareStatement(selectStatement);
            prepStmt.setInt(1,codio);
            rs = prepStmt.executeQuery();
            while(rs.next())
                 // use colomn names rather than indices
                 detalhes = new Detalhes(rs.getString(1), rs.getString(2), rs.getDouble(3), rs.getInt(4));
            rs.close();
            rs = null;
            prepStmt.close();
            prepStmt = null;
        // don't catch Exception
        }catch(SQLException sqle){
            // try and forget - is allways very useful
            Logger.getLogger(this.class.getName()).log(Level.SERVE, sqle.getMessage(), sqle);
        } finally {
           // close prepared statements and result sets within finally blocks
           if (rs != null) {
              try {
                 rs.close();
              } catch (SqlException sqle) {
                 Logger.getLogger(this.class.getName()).log(Level.FINEST , sqle.getMessage(), sqle) ;
           if (prepStmt != null) {
              try {
                   prepStmt.close();
              } catch (SQLException sqle) {
                  Logger.getLogger(this.class.getName()).log(Level.FINEST , sqle.getMessage(), sqle) ;
       return detalhes;
public final class ContextPage implements ServletContextListener {
    // don't use a member field here the context is passed within the event.
    private ServletContext context = null;
    // makes no sense to save it as member field.
    // what's NewClass ?
    NewClass bookDB;
    public void contextInitialized(ServletContextEvent event) {
        context = event.getServletContext();
        try {
            bookDB = new NewClass();
            context.setAttribute("bookDB", bookDB);
        } catch (Exception ex) {
            System.out.println("Couldn't create bookstore database bean: " +
                ex.getMessage());
    public void contextDestroyed(ServletContextEvent event) {
        context = event.getServletContext();
        NewClass dados = (NewClass) context.getAttribute("bookDB");
        if (dados != null) {
            dados.remove();
        context.removeAttribute("bookDB");              
<%-- I don't see where a bean with id dataSource and scope page is set
         if the bean does not exist a new bean will be created
         nobody ever calls the remove method of your Data bean
         what's param.theCode ?
--%>
<jsp:useBean id="dataSource" class="teste.Data" scope="page" >
       <jsp:setProperty name="dataSource" property="codigo"
value="${param.theCode}"/>          
</jsp:useBean>
}So now you've got a lot of work.
If you have fixed all the problems I've told you and you have still problems you can come
back and ask additional questions.
andi

Similar Messages

  • Date when the cube was filled with data for the last time

    Hi!
    We are using a SAP BW System and on top of it BOBJ for reporting. Within BEx Web Application Designer, it's very simple to access the data, when the cube was filled with data for the last time. Is it possible to access this information within BOBJ, too?
    Thanks for your help!
    Greetings
    Stefan

    Hallo Ingo,
    thanks for your answer. That was exactly what we were looking for.
    We will have to think about a workaround now.
    Greetings
    Stefan

  • Project Managers to know when a task has been updated for the last time

    Hi,
    I would like know if there is any timestamp feature in Project Server 2007, so that it can be possible for Project Managers to know when a task has been updated for the last time.
    Thanks in advance

    Hi,
    If you are using the My Tasks to drive the task updates then you can use the 'Applied Requests and Errors' available under 'Go To' in the Task Updates area. Here the PM can find when requests have been approved and how many updates he/she received for a
    particular task (by clicking the task name) etc.
    Hope this helps
    Paul

  • I didnt charge my iphone 5 for the recommended time,what should i do?

    I charged my iphone 5 for the first time for 3 hours and didnt charge for the 8hour which is the recommended time. My battery is now 100% and im scared that there will be a problem with my battery. What should i do?

    Don't worry about it, Apple has desgined the charging system of the iPhone to handle many kinds of charging events.
    I leave my phone on the charger every night so that it will always be ready to last me all day here in Austria. It's not technically "charging" for the 8 hours I sleep, it just means that the phone is running on external power.
    Plus, no iPhone will ever take 8 hours to charge, 3 hours is the max it will ever take to recharge.
    So, have no worries, and enjoy your new iPhone!

  • ACDSee has failed me for the last time.  What is a good image viewer?

    Hi Photo gurus,
    I've been using ACDSee for years. But I'm getting increasingly tired of it because it crashes often and seems to hang a lot. I'm curious to know what you people use as an image sorter, contact sheet maker and quick viewer? I'd prefer a stand alone program instead of bridge, because I need a cost effective solution.
    Thanks,
    Stan

    Hmmm, "hatred:
    i ...intense dislike or extreme aversion..."
    does indeed describe my feelings toward the entity that is MS. After an MBA that hopefully imparted an awareness of the right and wrong ways to compete, I have lived a lifetime watching MS's anti-competitive behavior impact the tech world. The US Supreme Court (effectively negated by actions of the GW Bush Administration) and the EEU both also sanctioned against MS for the illegal anti-competitive practices that MS made a successful business model of.
    Insofar as is feasible, I choose not to do business with the Enrons and the Microsofts of the world.
    And I also simply
    i dislike
    the OS, even though the nature of my work forces me to deal with it daily.

  • Can't change DVD region for the last time?

    I wish to change the DVD region setting on my emac and have one more left from the 5 changes allowed but when I try to change it, it comes up with an alert along the lines of "There was a problem changing the region on your drive." How can I resolve this? It is a newish 1.25ghz Superdrive model.
    PS. Someone commented here that perhaps the count of how many changes have occurred is incorrect? If so, how can I fix that? http://discussions.apple.com/thread.jspa?messageID=2279627&#2279627
    Also, the error doesn't seem to suggest I need to use a single-region DVD to set the new region as per here: http://docs.info.apple.com/article.html?artnum=31304

    I also am having this problem, was told to restart and hold down Alt Apple, P & R at the same time and wait for 3 dongs, and try to change region again, but did not work, I am stuck on region 1 need to change to region 2, the same problem it will be the last change.

  • My 2013 Macbook Air can't find my HPDeskjet 3050 printer. It worked fine before I took the Macbook away for the summer. What's wrong?

    My 2013 Macbook Air can't find my HPDeskjet 3054 wireless printer. They worked fine together before I took the MB away from the printer for the summer. I have tried reinstalling the HP software and a bunch of other things that didn't work. The printer shows up as its own wireless network in the list of networks, but then I have to disconnect from my home network and I lose internet connectivity. What's up?

    The printer shows up as its own wireless network in the list of networks
    It shouldn't.
    OS X: Connecting a Wi-Fi printer to your Wi-Fi network

  • What's wrong with these code?

    Hi, i made the below snippet of code for retriving data from a table in database. but it doesnt work property when i run the program. Could anyone tell me what's wrong with it? Thanx in advance.
    //rs is object of type ResultSet
    //url is one of the column names in a table
    <% if(rs.getString("url")!= null){%>
       <tr>
          <td>URL </td>
          <td>= { <%= rs.getString("url") %> },</td>   
      </tr>
    <%}%>

    Without seeing the error message, one can only guess. Some JDBC drivers do not allow you to get a column more than once, so that may be your problem. Store the result of rs.getString("url") in a String variable in the first line, and use that variable in the table cell.

  • HT1725 My Visa account keeps getting declined at Apple.I used this very same Visa card on Amazon with no problem. I checked my status for the card and it is still all good. Please let me know as soon as possible

    My Visa account keeps getting declined at Apple. I used this very same Visa card on Amazon with no problem. I checked my status for the card and it is still all good. My friends and I buy a lots of Apple applications on iTune.
    We have the correct CVV2, Expiration Date and Billing address, but you keeps declining us. Please fix this problem for me. The issuing bank for this card is Eximbank, one of the largest banks in Vietnam. According to the bank, the transaction is processed in the US. This is a legitimate Visa card.
    Please let me know as soon as possible. Apple does a disservice to its brand name by declining legitimate Visa account holders from using the cards in Vietnam.
    Sincerely,
    <Personal Information Edited by Host>

    These are user-to-user forums, you are not talking to Apple here - I've asked the hosts to remove your credit card number from your post as these are public forums (you should consider getting a new card from your provider as you've posted it here).
    Your card is registered to exactly the same address (spacing and format) as is on your iTunes account ?You can contact iTunes support via this page : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • My icloud eMail got updated on 06/11 for the last time.

    Since then I am getting the "cannot get mail connection to the server failed" message on my ipad. Apples support site is not too helpful. Went throught the suggested steps numerous times. Tried different wireless networks with same result. Same issue with MacBook. Cannot access my emails.

    This may help-->  http://support.apple.com/kb/HT1495

  • For the last time, how do I get rid of Facemoods? I hate it!

    There is a facemoods bar that is so distracting that I cannot do a search for anything else. I am ready to leave Firefox. I see from a search for a solution that I am not the only user who is disgusted with facemoods. It is juvenile and irritating.

    You have given me no solution understandable to a non geek. I will just go to Internet explorer and try my luck.

  • When i open a new tab even i have set the start page in "blank" babylon home page keeps coming on.always on new tab.never when i open firefox for the first time. what can i do to fix the problem?

    i tried to find any babylon programs on my computer but i didnt found something.

    '' get rid of babylon toolbar and get back home page"
    see the first answer, the one from the-edmeister in
    :https://support.mozilla.com/en-US/questions/860950

  • MY TOP BUTTON IS STUCK FOR THE SECOND TIME, WHAT SHOULD I DO?

    This phone has had no problems whats so ever,  but my top button isn't working anymore.  This happened to my other iphone and Im trying to avoid going to a store.  What can I do to fix it?

    It's broken.  If you can't be bothered to "go to a store", then live with it.

  • Unknown error occurs when I connect my iphone to itunes for the first time, what does that mean

    Everytime I connect my iphone to my laptop and start up itnes get an error messaage stating that an error has occurred and my phone can not be read

    Read here:
    http://support.apple.com/kb/ht1207

  • Local references for the last time..:-)

    I'm getting NUTS with this...please is it possible determine in Visual C++ which local references in JNI are not deleted????

    You have given me no solution understandable to a non geek. I will just go to Internet explorer and try my luck.

Maybe you are looking for

  • Exporting to Excel from Aria People Search

    Is it possible to export to Excel from Aria People Search. I would like to output the Org Chart (built in) and the Tree (I created) to an Excel file. Does anyone know how to do this? Thanks, Tom

  • [beginner] I need to take data from 4  in Numbers '09 and combine info

    I need to take 4 cells of data that has name and address in column and combine all cell information into a single cell in address format so it can be copied and pasted onto labels. e.g. A1 cell: John A2 cell" smith A3 city A4 state A5 zip code how ca

  • Error while running Java Web Start in JDK 1.5

    I have been running an application using Jboss3.2 in JDK1.4.2_09. The Java Web Start application ran perfectly then. Now, I am running Jboss3.2 with JDK 1.5.0_11. While some applications (HTML client and some Java Web Start applications are working c

  • Can't input birthday previous to 2000 in address book

    The birthday field in address book won't let me input a date older than the year 2000.  I assume there's a way to change that but didn't find anything in the preferences menu. Can somebody help me? Thank you!

  • Preflight XML report differs from droplet report

    Hi all, When i create a xml-report 'by hand' with the preflight tool, it generates much more info then when i use the same preflight profile as a droplet. In this case i want to extraxt info about page-size and color-separations per page. In the 'han