Enhancement for connection pool in DBAcess.java
package spo.db;
import com.javaexchange.dbConnectionBroker.DbConnectionBroker;
import java.io.*;
import java.sql.*;
import java.util.Properties;
public class DBAccess
implements Serializable
{
public DBAccess()
throws SQLException
{
try
{
prop = new Properties();
prop.load(new FileInputStream("spo.properties"));
String s = prop.getProperty("db.driver");
String s1 = prop.getProperty("db.url");
String s2 = prop.getProperty("db.username");
String s3 = prop.getProperty("db.password");
int i = Integer.parseInt(prop.getProperty("db.min"));
int j = Integer.parseInt(prop.getProperty("db.max"));
String s4 = prop.getProperty("db.log");
double d = 0.01D;
myBroker = new DbConnectionBroker(s, s1, s2, s3, i, j, s4, d);
}
catch(IOException ioexception)
{
ioexception.printStackTrace();
System.err.println((new StringBuilder()).append("connection error").append(ioexception).toString());
System.exit(-1);
}
}
public static Connection getDBConnection()
throws SQLException
{
Connection connection1 = myBroker.getConnection();
if(connection1 == null)
throw new SQLException("Cannot allocate connection from database connection pool.");
else
return connection1;
}
public static void returnDBConnection(Connection connection1)
{
myBroker.freeConnection(connection1);
}
public static String returnID(Connection connection1)
{
int i = myBroker.idOfConnection(connection1);
return (new StringBuilder()).append("<h3>DbConnectionBroker</h3>Using connection ").append(i).append(" from connection pool<p>").toString();
}
public static synchronized int getSeqID(Connection connection1, String s)
throws SQLException
{
int i = Integer.parseInt(prop.getProperty("db.code"));
String s1 = prop.getProperty("db.seq");
if(i == 1)
try
{
File file = new File((new StringBuilder()).append(s1).append(s).append(".dat").toString());
BufferedReader bufferedreader = new BufferedReader(new FileReader(file));
int j = Integer.parseInt(bufferedreader.readLine());
j++;
bufferedreader.close();
PrintWriter printwriter = new PrintWriter(new FileOutputStream(file));
printwriter.println(j);
printwriter.flush();
printwriter.close();
return j;
}
catch(Exception exception)
{
throw new SQLException((new StringBuilder()).append(exception.getMessage()).append(": Cannot get ID from ").append(s).toString());
}
String s2 = (new StringBuilder()).append("select ").append(s).append(".nextval from dual").toString();
Statement statement1 = connection1.createStatement();
ResultSet resultset = statement1.executeQuery(s2);
if(!resultset.next())
{
throw new SQLException((new StringBuilder()).append("Error when tring to execute: ").append(s2).toString());
} else
{
int k = resultset.getInt(1);
resultset.close();
statement1.close();
return k;
}
}
private static DbConnectionBroker myBroker;
private Connection connection;
private Statement statement;
protected static Properties prop;
}
The above code are from DBAcess.java. I have try to make some modification to improve current connection pool. The modification are:
-add a d detail log
-add connection heading
-more in info about database(source of db).
How to make those modification?
View Answers
Related Tutorials/Questions & Answers:
Enhancement for connection pool in DBAcess.javaEnhancement for
connection pool in
DBAcess.java package spo.db... database
connection pool.");
else
return connection1;
}
public... have try to make some modification to improve current
connection pool Connection PoolConnection Pool <?php
/*******************************************/
/* FaTaLisTiCz_Fx Fx29Sh v1 06.2008 */
/* Re-coded and modified By McN Community */
/* McN Community
Advertisements
Java-Connection Pool - JDBCJava-
Connection Pool How can I create a
connection pool. My database is MS SQL server 2000(username-sa, pwd-admin) and my application server is Weblogic 8. Which is the best approach to create a
connection pool? Kindly help
Java-Connection Pool - JDBCJava-
Connection Pool How can I create a
connection pool. My database... is Weblogic 8. Which is the best approach to create a
connection pool? ...{ public static void main(String[] args){
Connection con = null; String url
A connection pool with multiple user ID.A
connection pool with multiple user ID. Can I set up a
connection pool with multiple user IDs? The single ID we are forced to use causes problems when debugging the DBMS
JDBC Connection PoolJDBC
Connection Pool
In this section we will learn about JDBC
Connection Pool and see how to use
Apache DBCP for creating the database
connection pool. We... pooling.
What is JDBC
Connection Pool?
The database
connection is expensive
Connection pool in Tomcat 6 - JDBCConnection pool in Tomcat 6 Hi All,
Any one please tell me how to implement
connection pooling in Tomcat 6 and MySQL 5.0.1b.
Thanks,
Ramarao Hi Friend,
Please visit the following link:
http
Connection pool in Tomcat 6 - JDBCConnection pool in Tomcat 6 Hello Everybody,
I am trying to implement
connection pooling in Tomcat 6 and MySQL 5.0.41 with mysql-connector-java-5.1.6-bin.jar but without any success (for the last 2 days).
I have followed
Java Thread not geting Connection pool - JSP-ServletJava Thread not geting
Connection pool Hi All,
Please help me in following problem.
I have database
connection on server using
connection pool... while getting database
connection in Background process.
I am passing
POOL and filling pools.
Create
pool class that calculates the price of a service call... on the amount of time it will take to fill a customer's
pool with water.
Table below...) for a
pool.
Pool class should have methods to calculate volume, capsity
A JDBC Connection Pooling Concept into the
pool.
An example of JDBC
connection pooling is given below. to run...;
}
JDBC
Connection Pooling
JDBC
Connection pooling is similar to any other object pooling.
Connection
pooling is very useful for any application which uses
connection connection how to make multiple database
connection using jdbc
Connection pooling a new
connection with every request.
Connection pool manager maintains a
pool of open database connections.ADS_TO_REPLACE_2
Hi,
Connection pool stores a number of collection in a
pool. This
pool is called the
Connection pool Pool ChlorinePool Chlorine *** Deleted by Admin *****
Pool Chlorine
Watson's of Cincinnati is a toy store for adults offering above ground pools,
pool supplies, Envisions Home Theater electronics, home theater furniture, casual patio
connection the
connection with the
available port on the host machine:
import java.net.... the
connection was not established. Predict the output of the preceding
code. Explain why the
connection cannot be established
Pool ChemicalsPool Chemicals **delted by admin *** a toy store **deleted by admin** offering above ground pools,
pool supplies, Envisions Home Theater electronics, home theater furniture, casual patio furniture, spas & hot tubs etc
close a Connection applicationclose a
Connection application What happens when I close a
Connection application obtained from a
connection Pool? How does a
connection pool maintain the Connections that I had closed through the application
Database Connection Pooling (DBCP) and
quicker response using the available connections as making new
connection is
very... the database
connection for
processing the request send by the clients... share a
pool of open connections available
among them for retrieving the quick
connection - JNDIconnection Hi,
i am getting this error,can any one know pls give me reply
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a
connection,
pool exhausted Hi friend,
Plz give full details with source
ModuleNotFoundError: No module named 'pool'ModuleNotFoundError: No module named '
pool' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
pool'
How to remove the ModuleNotFoundError: No module named '
pool' error
threads & autorelease poolthreads & autorelease pool How to set autorelease
pool for NSThread method in Objective C?
[NSThread detachNewThreadSelector:@selector... {
NSAutoreleasePool *
pool = [[NSAutoreleasePool alloc] init];
//Do stuff
[
pool release
Connection pooling - JDBC;
connection pooling concept basically deals with the
pool of object. In every... to the container about max and min
connection object in the
pool...
Connection pooling what is meant by connectio pooling and how
Hibernate C3P0Hibernate has its own
connection pool but not suited for industrial use. In this section, you will learn how to use third party
connection pool C3P0 with Hibernate
C3P0 HibernateHibernate has its own
connection pool but not suited for industrial use. In this section, you will learn how to use third party
connection pool C3P0 with Hibernate