Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC Enhancement for connection pool in DBAcess.java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


NOR AZILA BT ZULKIFLI
Enhancement for connection pool in DBAcess.java
0 Answer(s)      3 years and 3 months ago
Posted in : JDBC


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?


Advertisement
View Answers

Related Tutorials/Questions & Answers:
Enhancement for connection pool in DBAcess.java
Enhancement 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 Pool
Connection Pool  <?php /*******************************************/ /* FaTaLisTiCz_Fx Fx29Sh v1 06.2008 */ /* Re-coded and modified By McN Community */ /* McN Community
Advertisements
Java-Connection Pool - JDBC
Java-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 - JDBC
Java-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
how to writw connection pool coding
how to writw connection pool coding  java connection poolprint("code sample
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 Pool
JDBC 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 - JDBC
Connection 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 - JDBC
Connection 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-Servlet
Java 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
Pool Chlorine
Pool 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
Pool Chemicals
Pool 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
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  What is Connection
connection
connection   how to make multiple database connection using jdbc
threads & autorelease pool
threads & 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
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
swimming pool calculator
swimming pool calculator  i'm writing a program to calculate the measurements of a swimming pool & a hot tub. and then the user can enter... of swimming pool(ft):"); lengthLabel.setBounds(10, 15, 260, 20
Connection pooling
connection with every request. Connection pool manager maintains a pool of open database connections.   Hi, Connection pool stores a number of collection in a pool. This pool is called the Connection pool. In your Java program you can
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... within a single point of time. In this process, the programmers share a pool
Questions about Java's String pool
Questions about Java's String pool  Questions about Java's String pool
close a Connection application
close 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
Swimming Pool Calculator - Java Beginners
Swimming Pool Calculator  I have to write a program to calculate the volume of a swimming pool. The assignment is as follows: This Swimming Pool... depth of a pool and the program will calculate the volume of that pool based
Swimming Pool Calculator - Java Beginners
Swimming Pool Calculator  When I run the program the login window...()); mainFrame = new JFrame("Swimming Pool Volume Calculator"); calcButton = new... JTextField(5); lengthLabel = new JLabel("Enter the length of the swimming pool
connection - JNDI
connection   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
Swimming Pool Calculator - Java Beginners
Swimming Pool Calculator  Okay, so I tried making the program... ); JLabel lengthLabel = new JLabel( "Enter the length of swimming pool(ft... of the swimming pool(ft):" ); widthLabel.setBounds( 10, 60, 260, 20 ); pools.add
C3P0 Hibernate
Hibernate 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
Hibernate C3P0
Hibernate 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
class NSCFString autoreleased with no pool in place - just leaking
class NSCFString autoreleased with no pool in place - just leaking  Hi, In my application following error is coming: class NSCFString autoreleased with no pool in place - just leaking What is the solution? Thanks
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
Advertisements
 

 

 

DMCA.com