0

Hello can any one tell me how to use connection pooling concept i am having normal java methods in which i am using DriverManager() and getConnection(). methods to connect to Database i am creating new connection foe every call and i am closing it manually in Try catch block but my application is very slow while populating hundreds of records. I am not using any servlets or jsp i am just developed one deskto application please help me thanks you in advance.

Prakash
  • 11
  • 1
  • 1
  • 4

3 Answers3

1

You can use Apache's DBCP package for connection pooling.Check below link.

http://commons.apache.org/dbcp/api-1.2.2/org/apache/commons/dbcp/package-summary.html#package_description

Metalhead
  • 1,429
  • 3
  • 15
  • 34
  • thnk you for responding i am using MYSQL database and Zend server will it work for that also. – Prakash Oct 19 '12 at 06:23
  • It should work. Why dont u try it? – Metalhead Oct 19 '12 at 08:19
  • i tried commons-pool16.jar file and methods in that jar file but it won't work for me it create connections first properly i am returning all connections in finally method but after some time it gives error like Java CustomException: and message is too many connections. – Prakash Oct 29 '12 at 08:09
0

Another way than Metalhead mentioned is to use a Java EE Application Server such as Glassfish and EJBs. Once you configured your Database as a resource in the application server, then you can just inject your EntityManager (JPA) or DataSource (JDBC) and the application server will take care of handling the connections.

Puce
  • 37,247
  • 13
  • 80
  • 152
  • Why should he use a full on J2ee server for his desktop application? – Metalhead Oct 19 '12 at 08:18
  • It depends on the application. As soon as you have multiple users and application logic, most of the time you want to control this on the server - also with desktop clients, not only with web clients. – Puce Oct 19 '12 at 09:03
0

There are 3 connection functions:

mysql_connect: normal connection, no pooling, you cannot execute stored procedures (just sql)

mysql_pconnect: pooled connection, you cannot execute stored procedures (just sql)

mysqli_connect: normal connection, no pooling, you can execute stored procedures (needs mysql 5 or higher)

for reference : click here

Sasi Kathimanda
  • 1,788
  • 3
  • 25
  • 47