Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #22358
| Date | 2013-02-19 09:18 +0000 |
|---|---|
| From | lipska the kat <"nospam at neversurrender dot co dot uk"> |
| Organization | Trollbusters 3 |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: how to access connection object in another class? |
| References | <9345656c-d843-4e20-a49a-df3b3fd7dfe5@googlegroups.com> |
| Message-ID | <CvadnZQc_J_i3r7MnZ2dnUVZ8j-dnZ2d@bt.com> (permalink) |
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
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how to access connection object in another class? xodepp shrestha <xodepp@gmail.com> - 2013-02-19 00:18 -0800
Re: how to access connection object in another class? Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-02-19 04:48 -0400
Re: how to access connection object in another class? jlp <jlp@jlp.com> - 2013-02-19 09:50 +0100
Re: how to access connection object in another class? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-02-19 09:18 +0000
Re: how to access connection object in another class? markspace <markspace@nospam.nospam> - 2013-02-19 09:43 -0800
Re: how to access connection object in another class? Lew <lewbloch@gmail.com> - 2013-02-19 11:39 -0800
Re: how to access connection object in another class? Roedy Green <see_website@mindprod.com.invalid> - 2013-03-01 00:20 -0800
csiph-web