Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Moving method from one class to another breaks it

 
Pedro Mondino
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following method is part of a program i am writing for school. I originally had it contained in my main class (GuiClass) which extends javax.swing.JFrame.
I have a students class which extends GuiClass, and finally an Undergraduate class which extends the Students class. updateInfo() does not work when it is moved
to the undergraduate class, and i have to have it there per the task instructions. I've been working on this issue for days, and can't figure out what i am doing wrong.


I am thinking it may have something to do with the result set sharing. The rs is created in the GuiClass using



and the display info method is




Just to reiterate, updateInfo() works fine in GuiClass, but does not update the database when i move it to another class. Any help i could get would be greatly appreciated!
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pedro. Welcome to The Ranch!

So how are you calling updateInfo? And how are you calling it when you move it to another class?

One thing that looks dodgy, though, in both updateInfo and displayInfo, is using an instance variable (I assume) for your ResultSet. It would be much better to declare that as a local variable and then pass it in to the methods that need it. I don't know if that's related to your problem, but it would definitely be an improved design.
 
Pedro Mondino
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the lack of info >_<

while it is in the GuiClass, i am just calling the method in a jButton action using


while it is in the Undergraduate class (and not working) i am using (in the same button code)


and my ResultSet and statement variable are declared as:

at the beginning of my program. Thanks for the very speedy reply
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So is Undergraduate an inner class of GuiClass? How is it accessing the ResultSet variable in GuiClass?

Anyway, I'd definitely do what I suggested earlier. You need to make sure a suitable ResultSet is opened when you press the button, so I'd use a local variable and open it when you need it (and close it again afterwards).
 
Pedro Mondino
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the class layout, Undergraduate extends Students extends GuiClass. Students is an abstract class with abstract methods, to force Undergraduate (and other classes i havent made yet), into implementing the methods.

I had the first result set as a global variable in order for the GUI to always have a row displayed in the jtextfields, so i was trying to do something similar when adding more resultsets. The way i had it working originally, the program has navigation buttons(first,last,next,previous) which display the row contents into the corresponding fields. It also has other buttons (new record, update record, delete record, and a query function), which also use the first result set to keep the information displayed to the frame/fields.

I am trying to follow your advice now from yesterday about switching the variables scope, trying to get it to work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic