Putting Resultset objects in an Vector

Can anybody help me, I have to put all my results from the ResultSet in a Vector.
But I don't know how.
Thanx in advance.

for a vector of vector ....
public static Vector prepareData(ResultSet rs)
     Object lValue=null;
     Vector returnedVector=new Vector();
     try
          Enumeration lEnum=null;
          rs.beforeFirst();
          while (!rs.isLast())
               lEnum=this.elements();
               Vector lLine=new Vector();
               int i=0;
               rs.next();
               while (lEnum.hasMoreElements())
                    lValue=rs.getObject(i);
                    lLine.add(lValue);
                    i++;
               returnedVector.add(lLine);
     catch (SQLException e)
          e.printStackTrace();
     return returnedVector;          

Similar Messages

  • Putting a Class Object into a Vector

    HI all
    I need to put a class object into another classes vector, then be able to read it and retrieve data.
    I can put the object into the vector but all i seem to be able to retrieve is data like Account@2343c2.
    Is this some sort of tag? How do i get to the data?
    thankz
    joey

    That's what you get when you print an object which does not have its own toString() method to do anything different - it picks up the Object class's toString method instead. For example:
    System.out.println(new Object());It sounds like you're doing something like this:
    Vector v = new Vector();
    v.add(new Account(42));If you were to do the following, you would see that sort of output:
    System.out.println(v.get(0));The appropriate way to do this would be something like the following:
       // Use a List reference instead of a Vector reference, and create
       // an ArrayList object in preference to a Vector object
       List list = new ArrayList();
       list.add(new Account(42));
       // Iterate through the list of accounts - use an
       // iterator because this prevents off-by-one errors
       // that arise with direct indexing.
       Iterator i = list.iterator();
       while(i.hasNext()) {
          // Cast the reference returned by the iterator from
          // Object to Account so that we can call account-specific
          // methods.
          Account current = (Account)i.next();
          // Call the method specific to the Account class (getBalance
          // is just an example that I made up).
          System.out.println(current.getBalance());
       }

  • How do I  print out the attributes of objects from a  Vector?  Help !

    Dear Java People,
    I have created a video store with a video class.I created a vector to hold the videos and put 3 objects in the vector.
    How do I print out the attributes of each object in the vector ?
    Below is the driver and Video class
    Thank you in advance
    Norman
    import java.util.*;
    public class TryVideo
    public static void main(String[] args)
    Vector videoVector = new Vector();
    Video storeVideo1 = new Video(1,"Soap Opera", 20);
    Video storeVideo2 = new Video(2,"Action Packed Movie",25);
    Video storeVideo3 = new Video(3,"Good Drama", 10);
    videoVector.add(storeVideo1);
    videoVector.add(storeVideo2);
    videoVector.add(storeVideo3);
    Iterator i = videoVector.interator();
    while(i.hasNext())
    System.out.println(getVideoName() + getVideoID() + getVideoQuantity());
    import java.util.*;
    public class Video
    public final static int RENT_PRICE = 3;
    public final static int PURCHASE_PRICE = 20;
    private int videoID;
    private String videoName;
    private int videoQuantity;
    public Video(int videoID, String videoName, int videoQuantity)
    this.videoID = videoID;
    this.videoName = videoName;
    this.videoQuantity = videoQuantity;
    public int getVideoID()
    return videoID;
    public String getVideoName()
    return videoName;
    public int getVideoQuantity()
    return videoQuantity;
    }

    Dear Bri81,
    Thank you for your reply.
    I tried the coding as you suggested
    while(i.hasNext())
    System.out.println( i.next() );
    but the error message reads:
    "CD.java": Error #: 354 : incompatible types; found: void, required: java.lang.String at line 35
    Your help is appreciated
    Norman
    import java.util.*;
    public class TryCD
       public static void main(String[] args)
         Vector cdVector = new Vector();
         CD cd_1 = new CD("Heavy Rapper", "Joe", true);
         CD cd_2 = new CD("Country Music", "Sam", true);
         CD cd_3 = new CD("Punk Music", "Mary", true);
         cdVector.add(cd_1);
         cdVector.add(cd_2);
         cdVector.add(cd_3);
         Iterator i = cdVector.iterator();
         while(i.hasNext())
           System.out.println( i.next() );
    public class CD
       private String item;
       private boolean borrowed = false;
       private String borrower = "";
       private int totalNumberOfItems;
       private int totalNumberOfItemsBorrowed;
       public CD(String item,String borrower, boolean borrowed)
         this.item = item;
         this.borrower = borrower;
         this.borrowed = borrowed;
       public String getItem()
         return item;
       public String getBorrower()
         return borrower;
       public boolean getBorrowed()
         return borrowed;
       public String toString()
          return System.out.println( getItem() + getBorrower());

  • Vector, calling a method of an object in a Vector

    hi and sorry for my poor english.
    problem:
    i have a Vector:
    Vector objects = new Vector();i put some Objects in this Vector:
    objects.addElement(new testObject());in the class testObejct() i've defined some methods like:
    public method1() {
        System.out.println("bla");
    }how can i call that methods now by my Vector?
    this doesn work :(
    objects.lastElement().method1();thanx :)

    The vector method lastElement() returns an Object type so you need to cast the Object retrieved to the correct type before you can call one of it's methods.
    Try something like
    testObject to = (testObject)objects.lastElement();
    to.method1();you can use instanceof to test if a class is a member of a particular type

  • Send a ResultSet object via RMI - won't work.

    Hi. I make a user interface to access MySQL database. The access to MySQL server is done from a remote location via RMI. The process to delete/update/create was succeed. The only problem is when I try to get(from the client computer) the ResultSet object, that come from invoking statementObject.executeQuery(myQuery) method, from the server Computer: it won't work. It said that the ResultSet object is not serialized(it is an interface). I need the ResultSet object for my client program since I will use it to set my AbstractTableModel class's object. Last goal is to put the AbstractTableModel object into the JTable constructor so I can see the result from a table.
    Is anyone can help me? I can not return the ResultSet object to the client since it is not serialized.

    I use the following solution using List. As List is Serlizable I can throw it across the network using RMI... it is also of course easy to access.......
    For users objects you need to throw across the network just simply make them implement Serializable
    In your ORM class accessing the DB:
    public List getSQLResults{
    Resultset SQLResults = statement.executeQuery(SQLQuery);
    Vector results = new Vector();
    while (SQLResults.next()){
    // create class object here if needed...
    results.add(SQLResults.getStrinf("COL_NAME");
    return results;In your GUI class..
    JTable theTable = new JTable();
    DefaultTableModel theModel = new DefaultTableModel();
    theModel.addColumn(SOME_COLUMN);
    try{
    List resultsData = ORMClass.getSQLResults();
    Iterator iterator = List.Iterator();
    while(iterator.hasNext()){
    iterator.next();
    theTableModel.addRow(SOME_OBJECT);
    theTable.setModel(theModel);
    catch(Exception ex){
    // exception rasied...... do something!!!
    }

  • Why can't I add an Object[] to a Vector ? super Object[] ?

    I don't understand why javac rejects these two statements:
        Vector<? super Object[]> v= new Vector<Object[]>();
        v.add(new Object[0]);cannot find symbol
    symbol : method add(java.lang.Object[])
    location: class java.util.Vector<capture of ? super java.lang.Object[]>
    v.add(new Object[0]);
    ^
    The type of v can only be one of these 4:
    Vector<Object[]>, Vector<Object>, Vector<Serializable>, Vector<Cloneable>.
    Therefore, I should always be allowed to add an Object[] to it, right?
    The following example is very similar, but this one is accepted by javac.
        Vector<? super Number> v= new Vector<Number>();
        v.add(42);I didn't find a relevant difference to the first example, nor something in JLS3 that would forbid it. Is this a javac bug?

    There is a difference between legal and practical. Practical is a matter of opinion. I thought I should try the combinations to see which make sense.
    I don't find it intuative that list.add(list.get(0)) should fail to compile.
    While the definitions have a logic of their own, some are very hard to put it into english exactly what they really mean. This means finding a practical purpose for them even harder.
    For example List<? super Object>
    add(x) is legal for non-arrays
    method(list) is illegal for method(List<Object>) but is legal for method(List<? super Object[]>)
    public class A {
        public static void foo(List<? super Object[]> l) {    }
        public static void foo2(List<Object[]> l) {    }
        public static void foo3(List<? extends Object[]> l) {    }
        public static void bar(List<? super Object> l) {    }
        public static void bar2(List<Object> l) {    }
        public static void bar3(List<? extends Object> l) {    }
        public static void bar4(List<?> l) {    }
        public static void main(String[] args) {
            {   // can be { Object, Object[] }
                List<? super Object[]> l = new ArrayList<Object[]>();
                l.add(l.get(0));  // illegal
                l.add((Object) null);  // illegal
                l.add((Integer) null);  // illegal
                l.add((Object []) null); // illegal
                l.add((Integer []) null); // illegal
                l.add((Integer [][]) null); // illegal
                foo(l); // List<? super Object[]> - legal
                foo2(l); // List<Object[]> - illegal
                foo3(l); // List<? extends Object[]> - illegal
                bar(l); // List<? super Object> - illegal
                bar2(l); // List<Object> - illegal
                bar3(l); // List<? extends Object> - legal
                bar4(l); // List<?> - legal
            {   // can be Object[] or (? extends Object)[]
                List<Object[]> l = new ArrayList<Object[]>();
                l.add(l.get(0));  // legal
                l.add((Object) null);  // illegal
                l.add((Integer) null);  // illegal
                l.add((Object []) null); // legal
                l.add((Integer []) null); // legal
                l.add((Integer [][]) null); // legal
                foo(l); // List<? super Object[]> - legal
                foo2(l); // List<Object[]> - legal
                foo3(l); // List<? extends Object[]> - legal
                bar(l); // List<? super Object> - illegal
                bar2(l); // List<Object> - illegal
                bar3(l); // List<? extends Object> - legal
                bar4(l); // List<?> - legal
            {   // Only allows wildcards, Object is illegal.
                List<? extends Object[]> l = new ArrayList<Object[]>();
                l.add(l.get(0));  // illegal
                l.add((Object) null);  // illegal
                l.add((Integer) null);  // illegal
                l.add((Object []) null); // illegal
                l.add((Integer []) null); // illegal
                l.add((Integer [][]) null); // illegal
                foo(l); // List<? super Object[]> - illegal
                foo2(l); // List<Object[]> - illegal
                foo3(l); // List<? extends Object[]> - legal
                bar(l); // List<? super Object> - illegal
                bar2(l); // List<Object> - illegal
                bar3(l); // List<? extends Object> - legal
                bar4(l); // List<?> - legal
            {   // can add non-arrays but can only match ? super Object, ? super Object[], or ? extends Object, but not Object 
                List<? super Object> l = new ArrayList<Object>();
                l.add(l.get(0));  // legal
                l.add((Object) null);  // legal
                l.add((Integer) null);  // legal
                l.add((Object []) null); // illegal
                l.add((Integer []) null); // illegal
                l.add((Integer [][]) null); // illegal
                foo(l); // legal
                foo2(l); // illegal
                foo3(l); // illegal
                bar(l); // legal
                bar2(l); // illegal
                bar3(l); // legal
                bar4(l); // legal
            {   // can add array but cannot call a method which expects an array. 100% !
                List<Object> l = new ArrayList<Object>();
                l.get(0).toString();
                l.add(l.get(0));  // legal
                l.add((Object) null);  // legal
                l.add((Integer) null);  // legal
                l.add((Object []) null); // legal
                l.add((Integer []) null); // legal
                l.add((Integer [][]) null); // legal
                foo(l); // legal
                foo2(l); // illegal
                foo3(l); // illegal
                bar(l); // legal
                bar2(l); // legal
                bar3(l); // legal
                bar4(l); // legal
            {   // cannot add any type but can match ? or ? extends Object.
                List<? extends Object> l = new ArrayList<Object>();
                l.add(l.get(0));  // illegal
                l.add((Object) null);  // illegal
                l.add((Integer) null);  // illegal
                l.add((Object []) null); // illegal
                l.add((Integer []) null); // illegal
                l.add((Integer [][]) null); // illegal
                foo(l); // List<? super Object[]> - illegal
                foo2(l); // List<Object[]> - illegal
                foo3(l); // List<? extends Object[]> - illegal
                bar(l); // List<? super Object> - illegal
                bar2(l); // List<Object> - illegal
                bar3(l); // List<? extends Object> - legal
                bar4(l); // List<?> - legal
            {   // same as ? extends Object.
                List<?> l = new ArrayList<Object>();
                l.add(l.get(0));  // illegal
                l.add((Object) null);  // illegal
                l.add((Integer) null);  // illegal
                l.add((Object []) null); // illegal
                l.add((Integer []) null); // illegal
                l.add((Integer [][]) null); // illegal
                foo(l); // List<? super Object[]> - illegal
                foo2(l); // List<Object[]> - illegal
                foo3(l); // List<? extends Object[]> - illegal
                bar(l); // List<? super Object> - illegal
                bar2(l); // List<Object> - illegal
                bar3(l); // List<? extends Object> - legal
                bar4(l); // List<?> - legal
    }

  • Unexpected behavior when creating Objects in a Vector

    I have a situation where Objects in a Vector appear to be getting corrupted. The context is this: I obtain a ResultSet from a database, create a Vector of Strings for each row, and a Vector of these row vectors for the entire ResultSet. This is passed to a method where a POJO is created for each row. This method returns a Vector of these POJOs. In the Object constructor, a String array of initial values is created and also values are assigned to individual variables. Here is a snippet with the Object constructor
    public class RefAuthorItem {
         private final String refKey;
         private String authorKey, firstName, lastName, itemKey;
         private int authorPosition;
         private boolean isDeleted, isNew;
         // Keep a copy of the original values
         private final String[] oldValues;
          * The constructor for the data object item.
          * @param dataVals     a String array of the data values
          * @param isNewVal     boolean true if this is a new item, false if it is
          *                                              an existing item
         public RefAuthorItem(final String[] dataVals, final boolean isNewVal) {
              oldValues = dataVals;
              authorKey = dataVals[RefQueryBuilder.AUTH_NUM];
              firstName = dataVals[RefQueryBuilder.AUTH_FIRST_NAME];
              itemKey = dataVals[RefQueryBuilder.AUTH_PKEY];
              lastName = dataVals[RefQueryBuilder.AUTH_LAST_NAME];
              refKey = dataVals[RefQueryBuilder.AUTH_REF_FKEY];
              isNew = isNewVal;
              isDeleted = false;
              // the author position integer value is used to sort the display
              authorPosition =
                        Integer.parseInt(dataVals[RefQueryBuilder.AUTH_POS]);
         }It seems the oldValues[] values should be identical to the corresponding individual variable values. When the following code is used to create the objects, they are not.
              final boolean isNew = isNewVal;
              Vector<RefAuthorItem> returnSet = new Vector<RefAuthorItem>();
              final String queryString = QueryBuilder
                   .getRefQuery(keyString, tableName);
              Vector<Vector> dataSet = QueryDB.getResultSet(queryString);
              int columnTot = dataSet.firstElement().size();
                    String[] itemVals = new String[columnTot];
              for (Iterator iter = dataSet.iterator(); iter.hasNext();) {
                   Vector element = (Vector) iter.next();
                   for (int i = 0; i < columnTot; i++) {
                        itemVals[i] = (String) element.get(i);
                   RefAuthorItem item = new RefAuthorItem(itemVals, isNew);
                   returnSet.add(item);
              }What happens is this. I returned four rows from the database and the oldValues[] array for each of the four corresponding objects contains the data from the fourth row. However, when I retrieve the corresponding individual values (e.g., authorLastName) from the Object, it is correct. I checked the object values (oldValues versus individual values retrieved via getters) right after the object is created (the line: RefAuthorItem item = new RefAuthorItem(itemVals, isNew);) and get the correct results. Also, results are correct when the itemVals constructor is moved within the loop, as below
              int columnTot = dataSet.firstElement().size();
              for (Iterator iter = dataSet.iterator(); iter.hasNext();) {
                   Vector element = (Vector) iter.next();
                   String[] itemVals = new String[columnTot];
                   for (int i = 0; i < columnTot; i++) {
                        itemVals[i] = (String) element.get(i);
                   RefAuthorItem item = new RefAuthorItem(itemVals, isNew);
                   returnSet.add(item);
              } There is a problem here. Am I missing a subtle Java issue with instantiating the String array within the loop? Or is there a problem with Vectors? Thanks!

    Dear ejp,
    In the non-working code, I rewrite the itemVals[], create a new RefAuthorItem using the itemVals[] and repeat. I checked the RefAuthorItem immediately after it was created (with println()) and the oldValues and individual String values in the object are concordant. However, after the loop is completed (all RefAuthorItems are created and added to the Vector), the oldValues[] in the objects all have the values from the last row. The individual String variables in the object all have the correct value from the ResultSet row.

  • How to store a DB row (multiple columns) from ResultSet object to hm/ht

    I am trying to store a DB row (which is containing ~150+ columns) from ResultSet Object to HashMap/Hashtable using the below code. But I wonder is, this not working and even do not get any error.
    dataslotHashmap.put(rsmd.getColumnName(i+1),rs.getObject(i+1));
    where "rsmd" ResultSetMetaData Object and "rs" is ResultSet Object.
    Need advice please

    Code snippet for reference:
    rs=stmt.executeQuery("select * from ......
    rsmd=rs.getMetaData();
    rs.next();
    int noc=rsmd.getColumnCount();
    for(int i=0;i<noc;i+=1) {
    dataslotHashmap.put(rsmd.getColumnName(i+1),rs.getObject(i+1));

  • Resultset Object

    can any one out there please tell me about how to retrive resultset object through RMI as resultset is not serializable? or should i have to do somthing other than RMI. (which actually i don't want to)

    You cannot send a ResultSet object through RMI, as you
    found out. But don't give up on RMI. Design your own
    object to hold your data, then read through the result
    set on the server and put the data into your new
    custom object. Make sure that's serializable, then
    you can send it through RMI.

  • Two resultset objects

    IS it possible to define two resultset objects with two different queries inside the same DB class?java.sql.SQLException: Invalid state, the ResultSet object is closed.
         at net.sourceforge.jtds.jdbc.JtdsResultSet.checkOpen(JtdsResultSet.java:299)
         at net.sourceforge.jtds.jdbc.MSCursorResultSet.next(MSCursorResultSet.java:1123)
         at DB5.getDetails(Daily_Quote_Response_report.java:238)
         at Daily_Quote_Response_report.main(Daily_Quote_Response_report.java:74)
    java.util.List items = null;
            String query;
            String query2;
            try {
                query =
                       "select * from oqrep_except_resp_summary";
                query2 = "select * from oqrep_except_resp_detail";
                Statement state = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                        ResultSet.CONCUR_READ_ONLY);
                ResultSet rs = state.executeQuery(query);
                ResultSet rs2 = state.executeQuery(query2);
              //cannot create two rs objects // ResultSet rs2 = state.executeQuery(query);
                items = new ArrayList();Edited by: bobz on 03-Dec-2009 11:16
    Edited by: bobz on 03-Dec-2009 11:16

    Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.

  • Using all types of resultset Objects i need a single program

    i think all of u know that there are 8 types of resultset objects are there in jdbc technology i.e
    # next() - moves the cursor forward one row. Returns true if the cursor is now positioned on a row and false if the cursor is positioned after the last row.
    # previous() - moves the cursor backwards one row. Returns true if the cursor is now positioned on a row and false if the cursor is positioned before the first row.
    # first() - moves the cursor to the first row in the ResultSet object. Returns true if the cursor is now positioned on the first row and false if the ResultSet object
    does not contain any rows.
    # last() - moves the cursor to the last row in the ResultSet object. Returns true if the cursor is now positioned on the last row and false if the ResultSet object
    does not contain any rows.
    # beforeFirst() - positions the cursor at the start of the ResultSet object, before the first row. If the ResultSet object does not contain any rows, this method has
    no effect.
    # afterLast() - positions the cursor at the end of the ResultSet object, after the last row. If the ResultSet object does not contain any rows, this method has no effect.
    # relative(int rows) - moves the cursor relative to its current position.
    # absolute(int n) - positions the cursor on the n-th row of the ResultSet object.
    Using all these result set methods i need a sample program all these methods must be used in a single program itself

    BalajiEnntech123 wrote:
    i think all of u know that there are 8 types of resultset objects are there in jdbc technology i.e I don't know who "u" are but they're wrong if they think there are "8 types of resultset objects are there in jdbc technology".
    They'd be especially wrong to think that the methods you mention are "types of resultset objects".

  • Scrollable/Read_only  ResultSet objects

    I am trying to create an instance of a scrollable/read_only ResultSet object with the following code:
    Statement stmt = con.createStatement(
    ResultSet.TYPE_SCROLL_INSENSITIVE,
    ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = stmt.executeQuery("SELECT * FROM ...");
    The Connection object has been made successfully but am getting an AbstractMethodError Exception at line 1.
    Can anyone please help me out here.
    Thank you.

    I don't believe the Oracle driver allows for
    read/only. I'll take a look at the Oracle website,
    and see if I can verify that.
    JoelSorry, I was wrong on this. From the Oracle JDBC documentation, it states that CONCUR_READ_ONLY is valid for the Oracle 8 and Oracle 9 drivers. Are you using classes12.zip or classes12.jar for your Oracle libraries?

  • Scrollable/Updateable ResultSet objects

    I am trying to create an instance of a scrollable/updateable ResultSet object with the following code:
    Statement stmt = con.createStatement(
    ResultSet.TYPE_SCROLL_INSENSITIVE,
    ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = stmt.executeQuery("SELECT * FROM sch.a");
    The Connection object has been made successfully but am getting an AbstractMethodError Exception at line 1.
    Can anyone please help me out here.
    Thanks
    I am using JDK 1.3.1 and JDBC 2.0

    I use this and works fine for me....let me know how it goes...
    ResultSet resultSetMultCond = null;
    Statement getMultPartCond = null;
    String sqlMultCond = null;
    sqlMultCond = "SELECT #PART,#CONDS,COUNT(*) AS MCOUNT FROM MYLIB WHERE #PART = 'A123' GROUP BY #PART,#CONDS ORDER BY #PART";
    getMultPartCond = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_SENSITIVE,java.sql.ResultSet.CONCUR_UPDATABLE);
    resultSetMultCond = getMultPartCond.executeQuery(sqlMultCond);

  • Can i open more than one Resultset object

    hi in my program i have to retrive data from three table and the data from three
    table i have to use in another one
    i wanna know that can we open more than one ResultSet object within one
    try{
    }catch{] block ( i means ResultSet rs = st.excuteQuery(query) more than one time for different -different tables)
    or there is any other way to do this

    You can only have one active result set per statement at a time.
    Depending on the driver you are using you might be able to have more than one active statement (and result set) on one connection. Or not.
    Try catch has nothing to do with that.
    If you are nesting result sets then it is likely you should be using a join (SQL) which would then only require one result set.

  • I created a vector and added objects, but the vector is empty

    I created an object called a facility, it accepts 2 strings in the creator but stores the data as a string and a float. as you can see from the code below, i have tried to create a vector object to contain facilitys and named it entries. when i add objects to this vector, the vectors size does not change, and i cannot access elements of it via their index. but when i print the vector out i can see the elements? what is going on here. i am very confused. ps, if it helps i havent worked with vectors much before.
    FacilitysTest.java
    import java.util.*;
    public class FacilitysTest {
         public static void main (String [] args) {
         Facilitys entries = new Facilitys();
         entries.add("Stage","3.56");
         entries.add("kitchen","5.00");
         entries.add("heating","2");
    //     System.out.println(entries.firstElement() );
         System.out.println("printing out entries");
         System.out.println(entries);
         System.out.println();
         System.out.println("There are "+entries.size()+" entries");
         System.out.println();
         System.out.println("modifying entry 2");
         entries.setElementAt(new Facility("lighting","1.34"), 2);
         System.out.println(entries);
         System.out.println();
         System.out.println("deleting entry 1");
         entries.remove(1);
         System.out.println(entries);
    }the following is what happens when i run this code.
    the number (0,1,2) is taken from a unique number assigned to the facility and is not anything to do with the facilitys position in the vector.
    printing out entries
    Facility number: 0, Name: Stage , Cost/Hour: 3.56
    Facility number: 1, Name: kitchen , Cost/Hour: 5.0
    Facility number: 2, Name: heating , Cost/Hour: 2.0
    There are 0 entries
    modifying entry 2
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 >= 0
    at java.util.Vector.setElementAt(Vector.java:489)
    at FacilitysTest.main(FacilitysTest.java:17)
    Press any key to continue . . .
    Facilitys.java
    import java.util.*;
    public class Facilitys extends Vector {
         private Vector entries;
         public Facilitys( ) {
                 entries = new Vector();
        public void add( String name, String price ) {
             entries.add((new Facility( name, price) ));
        public Facility get(int index) {
              return ((Facility)entries.get(index));
         public float total() {
              float total = 0;
              for (int i = 0; i<entries.size();i++) {
                   total = total + ( (Facility)entries.get(i) ).getPricePerHour();
              return total;
        public String toString( ) {
            StringBuffer temp = new StringBuffer();
            for (int i = 0; i < entries.size(); ++i) {
                temp.append( entries.get(i).toString() + "\n" );
            return temp.toString();
    }

    are you reffering to where i have public class
    Facilitys extends Vector {
         private Vector entries;
         public Facilitys( ) {
                 entries = new Vector();
    That's correct. That's your problem.
    i added the extends Vector, because without it i got
    the following errors
    C:\Documents and Settings\george\My
    Documents\University\JavaCode\CM0112\FacilitysTest.jav
    a:14: cannot find symbol
    symbol : method size()
    location: class Facilitys
    System.out.println("There are "+entries.size()+"
    " entries");That's because you haven't implemented a size method in your class.
    ^
    C:\Documents and Settings\george\My
    Documents\University\JavaCode\CM0112\FacilitysTest.jav
    a:17: cannot find symbol
    symbol : method setElementAt(Facility,int)
    location: class Facilitys
    entries.setElementAt(new
    w Facility("lighting","1.34"), 2);That's because you haven't implemented setElementAt in your class.
    C:\Documents and Settings\george\My
    Documents\University\JavaCode\CM0112\FacilitysTest.jav
    a:21: cannot find symbol
    symbol : method remove(int)
    location: class Facilitys
         entries.remove(1);
    ^That's because you haven't implemented remove in your class.
    /Kaj

Maybe you are looking for