JSP Incomplete Output

I'm going through this jsp tutorial on lynda.com.  There's a database with a couple dozen rows and the below code should return them but i'm only getting the first column of the first row returned.  Can anybody see why?
Thanx

<%@ page import="java.sql.*" %><%@ page import="java.io.*" %><%@ page import = "com.mysql.*" %><?xml version="1.0"?>
<tours>
<%      
     Connection connection = null;
     Statement statement = null;
     ResultSet result = null;
     
     try {
         Class.forName("com.mysql.jdbc.Driver").newInstance();
         connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tours", "root", "thebes");
/*         out.println("connected to database");               */
         statement = connection.createStatement();
         String s = "Select * from tour";
         result = statement.executeQuery(s);
         while(result.next()) {
        	   %>
        	   <tour>
        	        <tourId><% out.print(result.getString("tourID")); %></tourID>
        	        <tourTitle><% out.print(result.getString("tourTitle")); %></tourTitle>
        	        <packageId><% out.print(result.getString("packageID")); %></packageID>
        	        <packageTitle><% out.print(result.getString("packageTitle")); %></packageTitle>
        	        <description><% out.print(result.getString("description")); %></description>
        	        <price><% out.print(result.getString("price")); %></price>
        	        <difficutly><% out.print(result.getString("difficulty")); %></difficulty>
        	        <length><% out.print(result.getString("legnth")); %></length>
        	        <image><% out.print(result.getString("image")); %></image>
        	        <link><% out.print(result.getString("link")); %></link>
        	   </tour>
        	   <%
         }
      }
      catch(SQLException e) {
           out.println("error connecting to database");
           e.printStackTrace();
      }
%>

Open in new window

xoxomosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

xoxomosAuthor Commented:
If i remove the tags, then it loops through to return all rows in the database just in one single blob.
<%@ page import="java.sql.*" %><%@ page import="java.io.*" %><%@ page import = "com.mysql.*" %><?xml version="1.0"?>
<tours>
<%      
     Connection connection = null;
     Statement statement = null;
     ResultSet result = null;
       
     try {
         Class.forName("com.mysql.jdbc.Driver").newInstance();
         connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tours", "root", "thebes");
/*         out.println("connected to database");               */
         statement = connection.createStatement();
         String s = "Select * from tour";
         result = statement.executeQuery(s);
         while(result.next()) {
        	  
        	  
        	       out.print(result.getString("tourID"));
        	       out.print(result.getString("tourTitle")); 
        	       out.print(result.getString("packageID"));
        	       out.print(result.getString("packageTitle"));
        	       out.print(result.getString("description"));
        	       out.print(result.getString("price"));
        	       out.print(result.getString("difficulty"));
        	       out.print(result.getString("legnth"));
        	       out.print(result.getString("image"));
        	        out.print(result.getString("link"));
        	  
        
        	  
         }
      }
      catch(SQLException e) {
           out.println("error connecting to database");
           e.printStackTrace();
      }
%>
</tours >

Open in new window



<?xml version="1.0"?>
<tours> 142 Days Adrift the Salton Sea5From Desert to Sea The Salton Sea is saltier than the Pacific, an unusual feat for inland body of water. And even though its salinity has risen over the years, due in part to lack of outflows and pollution from agricultural runoff, it has attracted a small, but dedicated population. The sea itself offers recreational opportunities including boating, camping, off-roading, hiking, use of personal watercraft, photography and bird watching. The sea has been termed a "crown jewel of avian biodiversity," being a major resting stop on the Pacific Flyway, a migratory path for birds. 2 Days Adrift the Salton Sea includes two nights accommodations at the Bombay Beach Inn, boat rental at the Salton City Harbor, and a guided fishing tour. 3502error connecting to database </tours>
0
gurpsbassiCommented:
change your out.print() to out.println() to be more clear.
The last line in the XML looks suspicious "error connecting to database "
0
xoxomosAuthor Commented:
True, hadn't noticed that.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

xoxomosAuthor Commented:
Just looking at the brackets, i don't know how it falls into the catch unless the database disconnects early in the while.
0
gurpsbassiCommented:
Can you paste the output produced with out.println()?

Also initialise a counter outside your loop and print its value inside the loop and increment it. Its hard to tell how many rows are being printed.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
xoxomosAuthor Commented:
I can't see any difference in code, but the below seems to be working.  I did de-install and re-install that wamp.  On re-install i noticed a LOT more files in the  ..\..\..\phpmyadmin4.1.14 directory/folder.  Before it contained three folders and two files.  This time it contained seven folders and more than fifty files.


<%@ page import="java.sql.*" %><%@ page import="java.io.*" %><%@ page import = "com.mysql.*" %><?xml version="1.0"?>
<tours>
<%      
     Connection connection = null;
     Statement statement = null;
     ResultSet result = null;
       
     try {
         Class.forName("com.mysql.jdbc.Driver").newInstance();
         connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tours", "root", "thebes");
         out.println("connected to database");          
         statement = connection.createStatement();
         String s = "Select * from tour";
         result = statement.executeQuery(s);
         while(result.next()) {
        	
        	 out.print(result.getString("tourID"));
        	 out.print(result.getString("tourTitle"));
        	 out.print(result.getString("packageID"));
        	 out.print(result.getString("packageTitle"));
        	 out.print(result.getString("description"));
        	 out.print(result.getString("price"));
        	 out.print(result.getString("difficulty"));
        	 out.print(result.getString("length"));
        	 out.print(result.getString("image"));
        	 out.print(result.getString("link"));  
         }
      }
      catch(SQLException e) {
           out.println("error connecting to database");
      }
%>
</tours >

Open in new window

0
xoxomosAuthor Commented:
Output after re-install of  winamp.
testoutput.rtf
0
xoxomosAuthor Commented:
Mil gracias
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.