Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #22358

Re: how to access connection object in another class?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail
NNTP-Posting-Date Tue, 19 Feb 2013 03:18:55 -0600
Date Tue, 19 Feb 2013 09:18:53 +0000
From lipska the kat <"nospam at neversurrender dot co dot uk">
Organization Trollbusters 3
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120410 Thunderbird/11.0.1
MIME-Version 1.0
Newsgroups comp.lang.java.programmer
Subject Re: how to access connection object in another class?
References <9345656c-d843-4e20-a49a-df3b3fd7dfe5@googlegroups.com>
In-Reply-To <9345656c-d843-4e20-a49a-df3b3fd7dfe5@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 8bit
Message-ID <CvadnZQc_J_i3r7MnZ2dnUVZ8j-dnZ2d@bt.com> (permalink)
Lines 55
X-Usenet-Provider http://www.giganews.com
X-AuthenticatedUsername NoAuthUser
X-Trace sv3-sNCnZlolnOsb4XO3jgRBPSP3gdR853bA53SWwkAlpyfixcjFL21I8KY/kzUHCCL65lmQWFDBlGdREvM!9NSXBQqXBGq5jhQ5/bolla4y1yPhmbkxTHGrFOwAIeL4to9JKOpFNBOhGYPmplY99X7JejDA0lY=
X-Complaints-To abuse@btinternet.com
X-DMCA-Complaints-To abuse@btinternet.com
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 2445
Xref csiph.com comp.lang.java.programmer:22358

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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