*
The moose likes JDBC and the fly likes DataTap Connection pool usage? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "DataTap Connection pool usage?" Watch "DataTap Connection pool usage?" New topic
Author

DataTap Connection pool usage?

andrew beales
Greenhorn

Joined: Nov 04, 2002
Posts: 15
I wish to use A DataTap to select a Database name and detail from a Properties file.I want to use a Business Object, DAO, Connection Pool and POJO.
I have a Data Tap,BO template,DAO Template,Connection Pool example(From DAO example on this site "I wish to add transaction support.").
I need some guidance to how to link these together.
This is a stand alone Java Application(J2SE) to a Access Database.The POJO has a Heiracical structure.Her is some code:
BUSINESS OBJECT
public class UserBO { private static ResourceBundle db_Identity =ResourceBundle.getBundle("dBUsage");public Final DbType = db_Identity.getString("db"); private ConnectionPool pool; public UserBO() {//Call Method to load to type of DB DataTap con = DataTapFactory.getDataSourceAccessor (dbType); }
DATATAP
public class DataTapFactory { public Final accessUrl = accessDB_Properties.getString("url");public Final accessUsername = accessDB_Properties.getString("username");public Final accessPassword = accessDB_Properties.getString("password");public Final accessDriverName = accessDB_Properties.getString("driverName"); private static ResourceBundle accessDB_Properties =ResourceBundle.getBundle("accessDBProperties"); public static DataTap getDataSourceAccessor(String dbType) { if (dbType.equals("ACCESS")) { //connection ConnectionPool connPool = new ConnectionPool(accessUrl, accessUsername, accessPassword, accessDriverName); return conn; } return null; }}
CONNECTION POOL
Note:I don`t know whether line
this.(Connection)setAutoCommit(autoCommit);
Will work.
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; public class ConnectionPool{ private ArrayList _freePool; private String _url; private String _username; private String _password; private String _dbDriverName; public ConnectionPool(){ _freePool = new ArrayList(); } public ConnectionPool(String connectURL, String uName, String pWord, String driverName){ this(); _url = connectURL; _username = uName; _password = pWord; _dbDriverName = driverName; _createConnections(_url,_username,_password,_dbDriverName); } public synchronized Connection getConnection(boolean autoCommit){ if(_freePool.size() == 0){ //None Available //Create a new set of Connections _createConnections(_url,_username,_password,_dbDriverName); } //Last connection in the Array so that we save time on re-arranging the Array this.(Connection)setAutoCommit(autoCommit); return ((Connection)_freePool.remove(_freePool.size() - 1)); } public void closeConnection(Connection con){ System.out.println("Current size of Pool: "+_freePool.size()); _freePool.add(con); System.out.println("Size of Pool after connection closed: "+ _freePool.size()); } private void _createConnections (String connectURL, String uName, String pWord, String driverName){ try{ Class.forName(driverName).newInstance(); for(int i=0; i<10; ++i){ Connection con = DriverManager.getConnection (connectURL,uName,pWord); _freePool.add(con); } }catch(ClassNotFoundException ex){ System.out.println(ex); }catch(InstantiationException ex){ System.out.println(ex); }catch(IllegalAccessException ex){ System.out.println(ex); }catch(SQLException ex){ System.out.println(ex); } } }
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30379
    
150

Andrew,
Can you post the code using the UBB code tags? That makes it much easier to read.
Thanks,
Jeanne


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
andrew beales
Greenhorn

Joined: Nov 04, 2002
Posts: 15
I wish to use A DataTap to select a Database name and detail from a Properties file.I want to use a Business Object, DAO, Connection Pool and POJO.
I have a Data Tap,BO template,DAO Template,Connection Pool example(From DAO example on this site "I wish to add transaction support.").
I need some guidance to how to link these together.
This is a stand alone Java Application(J2SE) to a Access Database.The POJO has a Heiracical structure.Her is some code:
BUSINESS OBJECT

DATATAP

CONNECTION POOL
Note:I don`t know whether line
this.(Connection)setAutoCommit(autoCommit);
Will work.

Sorry about this format problem.
[ May 09, 2004: Message edited by: andrew beales ]
[ May 09, 2004: Message edited by: andrew beales ]
andrew beales
Greenhorn

Joined: Nov 04, 2002
Posts: 15
I wish to use A DataTap to select a Database name and detail from a Properties file.I want to use a Business Object, DAO, Connection Pool and POJO.
I have a Data Tap,BO template,DAO Template,Connection Pool example(From DAO example on this site "I wish to add transaction support.").
I need some guidance to how to link these together.
This is a stand alone Java Application(J2SE) to a Access Database.The POJO has a Heiracical structure.Her is some code:
BUSINESS OBJECT

DATATAP

CONNECTION POOL
Note:I don`t know whether line
this.(Connection)setAutoCommit(autoCommit);
Will work.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30379
    
150

Andrew,
Thanks for re-formatting the code. It's much easier to read now. Those classes all seem to relate to each other in a logical way. Did you have a specific doubt about something (other than the connection pool's auto-commit)?
I feel like I might not be understanding the question.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DataTap Connection pool usage?