• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

quick question

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic