• 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

Data class instance in client

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question in main i create an instance of Data class and pass it into the constructor of the client. I use global instance to pass to my Abstarct table model and I use it when i goto the local mode or network mode i create an new instance everytime i do a search for local is this ok?
I pass the data instance to client to build my Jtable and i can use it only once for the search criteria method if local connection but when I try to use it a second time database exception....
check my code
Data myInstance = null;//global variable
public FlyByNight(Data myData)//pass instance from main
{
myInstance = myData;
.
.
.
}//end of constructor
else if(source == searchButton)
{
if(localMode)

{
try {

Data myStuff = new Data("db.db");
Data myStuff = new Data("db.db");

if(criteria equals found text)//wild card populate all
{
.
DataInfo[] inputDataInfo = myInstance.criteriaFind(criteria);//global instance.
//DataInfo[] inputDataInfo = myStuff.criteriaFind(criteria);
//this is new instance but the global instance I can only use once but to correctly work every time i do a search i have to new an instance of data class but i would like to only use the global instance myInstance that is passed from main to client but it only works once for my search button if i try another search it bombs...but if i new an instance for every search it works fine but how can i use only the one instance?
Thanks Lisa..
.
.
}

else
{
}

}
catch(Exception ex)
{}
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's good that you recognize that creating an instance of Data for each criteriaFind invocation is wrong. You probably even want to stay away from passing in Data from main. Try to use interfaces to decouple your classes. I don't know what your design looks like but it seems everthing is tightly coupled together.
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Sam, It would seem like alot of IO overhead for my original idea..
With an Interface would I create the instance in the interface and then implement the interface for the client and others that would need the instance such as my abstractTableModel etc etc..
thanks Lisa
 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no reason why calling criteriaFind(criteria), a second time, on the member variable myinstance, should cause a database exception. There may be some error in your implementation of the criteriaFind() method or at some other place in your design. It is impossible to say from the snippets of code provided by you. Only you can ascertain that after studying your entire design and code. But definitely constructing a new data object for every criteriaFind() call must be avoided- As you yourself recogize- it is inelegant, inefficient and makes no sense.

[This message has been edited by Rahul Rathore (edited March 09, 2001).]
[This message has been edited by Rahul Rathore (edited March 09, 2001).]
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I see this highly. I will have to go to an IDE an use debug for I am using textpad editor it is hard top step through without a Java IDE..
Thanks Lisa
 
reply
    Bookmark Topic Watch Topic
  • New Topic