J
JGH
I'm trying to make some objects for accessing database tables. I have a
super class that connects and does inserts, updates, & deletes:
class dbtable {
protected Connection conn;
protected connect ()
{ ...}
private insert ()
{ ... }public update ()
{ ...}
public delete ()
{ ... }
}
public table1 extends dbtable { ... }
public table2 extends dbtable { ... }
Waht if I want table1 and table 2 to use the same connection? If I
instantiate table1 and table2, they won't automatically share the
connection. I could overload the connect method so that if you pass in a
Connection, it just sets it's onw conn to the object passed in. Then you
could optionally call it with an already established connection. Like
this:
class dbtable {
protected connect (Connection cn) {
this.conn = cn;
}
}
..
table1 t1 = new table1 ();
t1.connect();
tabl2 t2 = new table2 ();
t2.connect (t1.conn);
Good idea or no? Any better ideas?
super class that connects and does inserts, updates, & deletes:
class dbtable {
protected Connection conn;
protected connect ()
{ ...}
private insert ()
{ ... }public update ()
{ ...}
public delete ()
{ ... }
}
public table1 extends dbtable { ... }
public table2 extends dbtable { ... }
Waht if I want table1 and table 2 to use the same connection? If I
instantiate table1 and table2, they won't automatically share the
connection. I could overload the connect method so that if you pass in a
Connection, it just sets it's onw conn to the object passed in. Then you
could optionally call it with an already established connection. Like
this:
class dbtable {
protected connect (Connection cn) {
this.conn = cn;
}
}
..
table1 t1 = new table1 ();
t1.connect();
tabl2 t2 = new table2 ();
t2.connect (t1.conn);
Good idea or no? Any better ideas?