Solved

arrays in jsp

Posted on 2004-04-08
15
274 Views
Last Modified: 2010-04-01
i need to store the following values in an array as i loop through a mysql table retrieving them. how would i enter them in an array if there was more than one person in the table?

ResultSet rs = stmt.executeQuery("SELECT fName,lName FROM register");             
            String name = "";
            String surname = "";
      
            while(rs.next())
            {
                       name = rs.getString(1);
                       surname = rs.getString(2);           
                 }
0
Comment
Question by:Raftor
[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
  • 7
  • 5
  • 2
  • +1
15 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10788411
Better off using a Collection instead of an array, as they can dynamically increase in size as required.
you should create a new class to store your person details and then use something like:

List people = new ArrayList();
while(rs.next())
{
    name = rs.getString(1);
    surname = rs.getString(2);
    people.add(new Person(name, surname));
}
0
 

Author Comment

by:Raftor
ID: 10788437
sorry objects but thats went way over my head can you show me please.
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 10788497
your Person class would look like:

public class Person
{
   private String Name = null;
   private String Surname = null;

   public Person(String name, surname)
   {
      Name = name;
      Surname = surname;
   }

   public String getName()
   {
      return Name;
   }

   public String getSurname()
   {
      return Surname;
   }
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Raftor
ID: 10788606
how do i get the jsp page to recoginise the jave class after i compile the java class?
0
 

Author Comment

by:Raftor
ID: 10788750
it says,

C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\Project\applicants_jsp.java:102: cannot resolve symbol
symbol  : class Person

location: class org.apache.jsp.applicants_jsp
             
 people.add(new Person(name, surname));
0
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 10789173
Use import in your JSP
<%@ page import = "Person" %>
0
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 10789180
Hi,
If your Person class in the package then import the class with the package path. Eg: Your Person class is in com\jsp\util\Person.class then the import will be like

<%@ page import = "com.jsp.util.Person"%>

I hope it help.
0
 

Author Comment

by:Raftor
ID: 10790331
ive tried to import the file but it is giving me the error.

C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\Project\applicants_jsp.java:9: package classfiles does not exist
import classfiles.*;


my folder structure is C:\Project\WEB-INF\classes\classfiles
and i import the class files like this <%@ page import="classfiles.*" %>







0
 
LVL 2

Expert Comment

by:anthony_castillon
ID: 10790569
Did you create the Person class as objects did above?  If so, add a package declaration (e.g. package com.raftor). Then in your JSP, your import should be <%@ page import="com.raftor.*" %>.
0
 

Author Comment

by:Raftor
ID: 10790639
ya i created the class as objects showed.  I packaged it like the other java file with 'package classfiles;' and imported                                                <%@ page import="classfiles.*" %>
0
 
LVL 92

Expert Comment

by:objects
ID: 10795042
what directory is your jsp file in?
0
 

Author Comment

by:Raftor
ID: 10795103
my jsp file is in C:\Project and the java file i want to include is in C:\Project\WEB-INF\classes with the class file in C:\Project\WEB-INF\classes\classfiles
0
 
LVL 92

Expert Comment

by:objects
ID: 10795370
have u restarted tomcat?
0
 

Author Comment

by:Raftor
ID: 10796421
Got it cheers
Raftor.
0
 
LVL 92

Expert Comment

by:objects
ID: 10799278
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reading data  from excel sheet and displaying 1 93
struts exact match support 3 61
How can I   ajax html table  rows? 20 83
going to wrong jsp page 2 50
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…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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…

730 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