Sagewire Logo

Single Connection attempt

2 Message(s) by 2 Author(s) originally posted in java databases


From: francan00 Date:   Thursday, October 18, 2007
I'd like to create a single Database connection point that I can
use for several of my class es 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:@xxxxxxxxxxx:1234:orcl",
"scott", "tiger");
}
return activeConnection;
}
}

Now how'd 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.


From: Lew Date:   Thursday, October 18, 2007
wrote in message:
I'd like to create a single Database connection point that I can
use for several of my classes in my JAVA Web Application.



You already got a thread going on this question in clj.programmer under
"Create single Database connection". You don't need to multi-post your
question. Please don't. It is rude to fragment the conversation and to
repost after people have been trying to help you.

--
Lew



Next Message: date operations in jpql queries


Blogs related to Single Connection attempt

Antivirus Concerns in XP and .NET Environments
NET execution framework reminds many people of Java's model. In order for a Java applet to run, it must be executed in a Java Virtual Machine (JVM) environment. .NET executables (regular Windows 32-bit Portable Executables) run on top ...

EJB Interview Questions
The enterprise bean must not attempt to query a class to obtain information about the declared members that are not otherwise accessible to the enterprise bean because of the security rules of the Java language. ...

JAVA JDBC QUESTIONS
They were added originally to make things simple for folks writing Java programs that use a single-threaded ODBC driver. 21. Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection? ...

Well it definitely java wasnt five yeah I guess brute force is ...
I’m experiencing an odd issue with MySQL, I get permission denied for ‘root’@'localhost’ _ONLY_ when I attempt a GRANT, I can insert the users into the user table, and FLUSH PRIVILEGES, there is no issue there. ...

New in D6 Platform: LDAP Integration Enhancements
D6 makes LDAP authentication support more robust by adding the ability to retry connection attempts and the ability to use secondary LDAP servers for failover, when the primary LDAP server is not available. ...

connecting satellite to tv
... connection anywhere connection api connection application connection architecture connection area connection asp net connection assigned connection assistant connection at philadelphia airport connection attempt connection attempt ...


Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional