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

x
?
Solved

arrays in jsp

Posted on 2004-04-08
15
Medium Priority
?
279 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 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Geo-targeting is the practice of distributing content based on a person’s location, as best as you can determine it. Let’s look at some ways you could successfully use this tactic. The following tips and case studies could lead to meaningful results.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

604 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