Solved

ODBC JSP ( Losing Variables..)

Posted on 2006-06-25
5
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to access elements of included jsp  from parent jsp's save button 9 28
grep code 4 207
maven set up 2 191
difference between sorce folder and folder in eclipise 3 45
Read  the original post  on Monitis Blog. Hi.  My name is Erik Dietrich, and this is the first time I’ve posted on the Monitis blog.  By way of introduction, I thought it would make sense to talk about my initial experience with Monitis.   Befo…
This article was originally published on Monitis Blog, you can check it  here . If you have responsibility for software in production, I bet you’d like to know more about it. I don’t mean that you’d like an extra peek into the bowels of the sour…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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