Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ODBC JSP ( Losing Variables..)

Posted on 2006-06-25
5
Medium Priority
?
294 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 100 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 100 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

618 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