File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Help with connection statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Help with connection statement" Watch "Help with connection statement" New topic
Author

Help with connection statement

nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
Hi,
I want the initialization of the database i.e.,

Class.forName(DEFAULT_DRIVER);
Connection connection = DriverManager.getConnection(DEFAULT_URL);

To be done in one method (in a class) and other methods should use this connection object inside.Is it possible to do something like this.Hope that you got my question correctly.
A reply would be appreciated.
Thanks
AS
Also adding,
What will be the return type of a method that will return a connection.Let me know thanks
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Have a look at using a DataSource instead (if you're using an aplication server) or use a ConnectionPool otherwise. (the ConnectionPool is usually hidden behind the DataSource in app servers. You get it for free)
They both allow you to put all the other 'stuff' elsewhere and just serve Connections.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with connection statement
 
Similar Threads
Datasource question
how to configure connection pooling in tomcat server?
how we should return a connection to connectio pool
Is the connection to the data base cossed properly.
Singleton class for Database Connection