Solved

ODBC JSP ( Losing Variables..)

Posted on 2006-06-25
5
265 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
ID: 16981442
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
ID: 16981706
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
ID: 17068567
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
loop through list of objects 14 186
How to group array of objects ? 5 60
build fail in maven project 11 179
equalIsNot  challenge 43 132
Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
When converting a physical machine to a virtual machine using VMware vCenter Converter Standalone or vCenter Converter Enterprise, if an adapter type is not selected during the initial customization the resulting virtual machine may contain an IDE d…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

9 Experts available now in Live!

Get 1:1 Help Now