Single Connection attempt



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.

.



Relevant Pages

  • Re: Illegal start of type...
    ... with a samples source CD or at least with a link to these samples on the ... > public class Hello { ... > Connection connection; ... > public void connectToDB() { ...
    (comp.lang.java.help)
  • Re: incompatible types?!
    ... > public class createTables { ... > private Connection connection; ... > It uses my DataBaseConnection connection class below (this class works ... > public class DataBaseConnection { ...
    (comp.lang.java.help)
  • Re: Getting data in class hierarchy (C#)
    ... Connection is reused while it is not being active. ... > If I want just the MoreSpecficUser data then I just call its Load() ... > public class MoreSpecficUser: User ...
    (microsoft.public.dotnet.framework.adonet)
  • Establishment of connection rejected (MySQL & Applet)
    ... The following code works as an application but not as an applet on the ... establishment of connection, message from server......Host ... I'm trying to run it from the server (localhost) and from another ... public class sqlapplet extends JApplet ...
    (comp.lang.java.databases)
  • Re: Optimising Connections & DataAdapters
    ... The connection object that you declare and instantiate is not the same as ... > a new SqlConnection in *every* DataLayer class? ... > public class ABC ... > SqlCommand cmd = new SqlCommand(sql, con); ...
    (microsoft.public.dotnet.framework.adonet)