aspose file tools*
The moose likes Beginning Java and the fly likes Custom jdbc function won't work in other classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Custom jdbc function won Watch "Custom jdbc function won New topic
Author

Custom jdbc function won't work in other classes

chris le
Greenhorn

Joined: Jul 30, 2004
Posts: 15
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 ]
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
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

Joined: Jul 30, 2004
Posts: 15
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
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
chris le
Greenhorn

Joined: Jul 30, 2004
Posts: 15
It worked!! Thanks Jules!

Take care,

Chris
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Custom jdbc function won't work in other classes