Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Single DB connection

Thread view: 
francan00@yahoo.com - 18 Oct 2007 08:06 GMT
I would like to create a single Database connection point that I can
use for several of my classes in my Java Web Application.

Here is my ConnectionManager Class:

public class ConnectionManager {
private static Connection activeConnection = null;
public static Connection getConnection() {
if (activeConnection = null) {
Class.forName("OracleThinInfoHere...");
activeConnection =
DriverManager.getConnection("jdbc:oracle:thin:@myname:1234:orcl",
"scott", "tiger");
}
return activeConnection;
}
}

Now how would I access the ConnectionManager in each one of my
classes?

For example here is one:

public class MainClass
{

public ConnectionManager.getConnection();
public Connection connection;

//I tried my db connection as this and it didnt return any results
public MainClass(connection)
{
this.connection = ConnectionManager.getConnection();
}

public int matcher(BeanClass abc)
{
try
{
new OtherDbClass(connection).insertDbMethod(abc);
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
//closing statements here
}

Another Class looks like this:
public class OtherDbClass {
private Connection connection;
public OtherDbClass(Connection connection)
{
this.connection = ConnectionManager.getConnection();
}

public int insertDbMethod(BeanClass abc)
{
...
...
}

Please advise.
Andrew Thompson - 18 Oct 2007 09:17 GMT
...
>Please advise.

Please refrain from reposting questions.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Lew - 18 Oct 2007 10:24 GMT
> ...
>> Please advise.
>
> Please refrain from reposting questions.

And reposting and reposting, multiple groups, reposting ...

Signature

Lew

Andrew Thompson - 18 Oct 2007 10:53 GMT
>> ...
>>> Please advise.
>>
>> Please refrain from reposting questions.
>
>And reposting and reposting, multiple groups, ...

A *multi-poster*!
<gravely>
Bring forth, the /comfy/ chair.
</gravely>

Signature

Andrew Thompson
http://www.athompson.info/andrew/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.