• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DataTap Connection pool usage?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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); } } }
 
author & internet detective
Posts: 41905
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Andrew,
Can you post the code using the UBB code tags? That makes it much easier to read.
Thanks,
Jeanne
 
andrew beales
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
author & internet detective
Posts: 41905
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 child proofed my house but they still get in. Distract them with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic