I have an abstract class called student with an abstract method add().
I also have other classes undergraduate, graduate, parttime that extends student. Requirements are that I have to have an abstract class student and the same abstract method add(). This method needs to write to mySQL DB elements entered (fistname, lastname etc...).
In my add() method under subclass undergraduate I can easily see the values from the textfield (System.out.println(this.firstname));
My question is: how can I easily implement something like sql.execute(this.firstname, this.lastname...); the same as println(this.firstname)?
Another question. Is opening the connection and closing it for a single SQL statement a requirement? I assume that I have to open the SQL connection at the beggining of the program and close it when the program ends outside and independent of the classes.
I don't want to open a connection to the database, write the record and close the connection, since I have to implement that for the other three subclasses and it's a lot of repeating code.
What I want is the same as println(this.firstname) but to write a record to the database.
I can't use an interface because student is an abstract class and as I said it is a requirement.
Any thoughts, examples are welcome... Thanks