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.
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 ]
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.
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:
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.
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.