Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Custom jdbc function won't work in other classes

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,
I wrote a class called 'RetrieveData' with a function that takes as it's arguments the jdbc driver, datasource, and sql code. It compiles fine without error.
However, once I bring it into another class, the other class doesn't recognize the variables from the 'RetrieveData' class. I'm pretty new to Java, so any help would be much appreciated.

take care,

Chris

Here's the code and error messages:


[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ August 20, 2004: Message edited by: Dirk Schreckmann ]
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chris,

Make sure you compile your RetrieveData class before the one that depends on it and make sure that the directory that contains the dataTest sub-directory that contains the RetrieveData.class file is on your classpath. If that's the "current directory" you need to make sure . is on your classpath.

Note the Java convention for package names is all lower case.

Jules
 
chris le
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Jules,

They're both in the same directory. And It compiles fine (the RetrieveData class that is) and even instantiates fine inside the Family2 class, I can call it's setDB method and pass in the appropriate arguments, so I don't think it would be a classpath issue. How else would I call the myResultSet variable that belongs to the RetrieveData class inside the Family class.
This is the only way I know of:

RetrieveData rd = new RetrieveData();

while (rd.myResultSet.next()){
...
}

Any ideas?

Thanks and take care,

Chris
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get ya. That's the trouble when you don't post your code using the UBB CODE tags; I can never be bothered to read it properly. It would be good if you could edit your previous post to use them (re-paste the code with indentation).

Your problem is that the myResultSet variable is local to your setDB() method. You need to declare it and any other variables you want to access from other classes as a member variable outside the method. Ideally you would make it private and provide an accessor (getter) method to it, but let's just get it working as it is first.

HTH

Jules
 
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even though the program is using JDBC, this is an issue with basic Java rather than JDBC per se. So I'm going to move this to the Java in General(beginner) forum where Julian and the other guys and gals who are really good at explaining Java concepts can help you out.
 
chris le
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It worked!! Thanks Jules!

Take care,

Chris
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When posting code, please be sure to surround the code with the [code] and [/code] UBB Tags. This will help to preserve the formatting of the code, thus making it easier to read and understand.
 
She'll be back. I'm just gonna wait here. With this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic