• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

quick question

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there. OK this problem is doing my head in and I keep on encountering it whilst programming. In this particular case there are two classes involved...Rectangle and OMGraphicList. In the Rectangle class I execute a call to my database using JDBC and insert the results of my SQL statement into a simple vector object. This works fine. Below is a brief code snippet from the Rectangle class:
public class Rectangle
{
protected Vector idQueryVector = new Vector();
...
public void makeQuery(String query)
{
...
try
{
Connection cont = new Connection();
Statement stmt = cont.conn.createStatement();
OracleResultSet ors = (OracleResultSet)stmt.executeQuery(query);
while(ors.next())
{
String dbObject = (String) ors.getObject(1);
idQueryVector.add(dbObject);
}
System.out.println(idQueryVector.size()); //returns non-zero value
ors.close();
cont.conn.close();
}
catch(Exception sqlE){}
In the OMGraphicList class I also have populated a vector called idVector with values. I can output the vector elements without any trouble. What I need to do is to compare the values in this idVector and the idQueryVector from the Rectangle class. I try to do this in the OMGraphicList class by calling an instance of the Rectangle class as follows:
Rectangle rect = new Rectangle();
However when I execute the following print statement it returns 0 indicating that the idQueryVector is empty whereas it is not empty
System.out.println(rect.idQueryVector.size()); //returns zero
What am I doing wrong here. Do I need to put all the functionality in the one class in order to get it to execute. Cheers Joe
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a little hard to tell w/out the code for both classes, but from your description


I try to do this in the OMGraphicList class by calling an instance of the Rectangle class as follows:
Rectangle rect = new Rectangle();
However when I execute the following print statement it returns 0 indicating that the idQueryVector is empty whereas it is not empty
System.out.println(rect.idQueryVector.size()); //returns zero


When you say "Rectangle rect = new Rectangle()", you create a new instance of the "Rectangle" class. It has it's own "idQueryVector" which is set to a new (empty) vector upon creation (instantiation). So until you call the "makeQuery()" method on that new instance, the vector will be--and should be--empty.
It sounds like you may have two instances of the "Rectangle" class hanging around, one with a non-empty vector and one with an empty vector.
 
Enjoy the full beauty of the english language. Embedded in this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic