Solved

ODBC JSP ( Losing Variables..)

Posted on 2006-06-25
5
261 Views
Last Modified: 2010-04-01
I'm reading from a Database using an ODBC Connection. I'm having trouble looping through the ResultSets without losing variables or it completly just displaying blank. Before I had everything rs.getString(#) inside of the output statements, but that caused problems for some reason and now I had it somewhat workign when i definied variables to the getString() statements. But, now it's just stopping completely and just displaying 1 line of data??
 
---------------------------------JSP CODE HERE------------------------------------------
 String url = "jdbc:odbc:" + serverName;
  // CONNECTION CODE HERE

  ResultSet rs = stmt.executeQuery("BIG QUERY HERE RETURNS 13 COLUMNS")

        
      int loop_amount = 0;
      String img_link = null;
      int p=1;
      
      String Name = null;
      String TREND_Name = null;
      String FOLDER_Name = null;
      String PAGE_URL = null;
      String MAIN_Name = null;
      String output = null;
      String COLOR_Name = null;

      while (rs.next())
      {


      
      loop_amount = rs.getInt(1);
      MAIN_Name = rs.getString(3);
      PAGE_URL = rs.getString(5);
      
      
      
      output = "<li><a href=" + PAGE_URL + "<u>" + MAIN_Name + "</u></font></a><ul>";
      
      out.println(output);
            

      if(loop_amount != 1)
            {
            

                  for(p=1; p <= loop_amount;p++)
                  {
                        COLOR_Name = rs.getString(13);
                        TREND_Name = rs.getString(8);
                        Name = rs.getString(4);

                        
                        out.println("<li><font size=1 face=\"Verdana\" color=\"" + COLOR_Name + "\">" + Name + "</font></li>");
                        
                        
                        if(p!=loop_amount)
                        {
                              rs.next();
                        }
                  
                  }
            
                  
            
            }
            else
            {
                  Name = rs.getString(4);
                  COLOR_Name = rs.getString(13);
                  TREND_Name = rs.getString(8);
                  
                  
                  out.println("<li><font face=\"Verdana\" size=1 color=\"" + COLOR_Name + "\">" + Name + "</font></li>");
            }

      out.println("</li></ul>");      

      }

 --------------------------------END OF JSP CODE----------------------------
0
Comment
Question by:kak39
5 Comments
 
LVL 3

Expert Comment

by:runa_paathak
Comment Utility
Are you sure your query is returning more than one row? If you are sure it is returning more than one row, the only reason I can think of is that your loop_amount could be 0. That will mean it will come into the if block but not into the for loop. Print out loop_amount in the if block and find out.
0
 
LVL 2

Accepted Solution

by:
pankilmpatel earned 25 total points
Comment Utility
Try to remove data betweem

ResultSet rs = stmt.executeQuery("BIG QUERY HERE RETURNS 13 COLUMNS")
and
while (rs.next())

and put it before rs declaration

0
 
LVL 4

Assisted Solution

by:Meritor
Meritor earned 25 total points
Comment Utility
in this code :


              for(p=1; p <= loop_amount;p++)
               {
                    COLOR_Name = rs.getString(13);
                    TREND_Name = rs.getString(8);
                    Name = rs.getString(4);

                   
                    out.println("<li><font size=1 face=\"Verdana\" color=\"" + COLOR_Name + "\">" + Name + "</font></li>");
                   
                   
                    if(p!=loop_amount)
                    {
                         rs.next();
                    }
               
               }


Yor are reading the data from the recordset more then onetime as per JDBC api's documentation: "For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once."

In my openion please debug this code and your problem may be solved.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
change size of out.write buffer 1 80
session bean client machine 9 53
SimpleDateFormat.parse examples 19 84
getting param value 7 51
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now