what is connection pooling with example?

Answer Posted / dinesh

Connection pooling whic h use to Reuse the Connection
resource.To Avoid wastage of connection resources,So you
don't need to have new connection ,Instead of creating new
connection,You can use the connection from connection pool
resource
A database driver may contain a connection pool as part of
its services, through its implementation of the
javax.sql.DataSource interface. DataSource objects are used
with JNDI.

With example:
import java.sql.*;
import java.util.*;
import org.w3c.dom.*;
import DBConnectionManager;

public class XSQL {
static DBBroker pool = DBBroker.getInstance();
// <---- Pool code!

public static Element executeQuery(
String connectionName,
String statementId,
String statementText,
Document factory
)
throws SQLException
{
Connection connection = null;
DBConnection db = null;
// <---- Pool code!
try {
db = pool.getConnection(connectionName);
// <---- Pool code!
connection = db.getConnection();
// <---- Pool code!
Statement statement = connection.createStatement();
ResultSet resultSet =
statement.executeQuery(statementText);
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();

Element rowSet = factory.createElement("xsql:rowset");
rowSet.setAttribute("id", statementId);

for (int i = 0; resultSet.next(); i++) {
Element row = factory.createElement("xsql:row");
row.setAttribute("sequence", String.valueOf(i + 1));
rowSet.appendChild(row);

for (int j = 0; j &lt; columnCount; j++) {
String value = resultSet.getString(j + 1);

Element element = factory.createElement(
metaData.getColumnLabel(j + 1).toLowerCase()
);
row.appendChild(element);

if (value != null) {
element.appendChild(
factory.createTextNode(value)
);
}
}
}

resultSet.close();
statement.close();

return rowSet;
} catch (SQLException e) {
throw(new SQLException(statementText));
} finally {
if (connection != null) {
pool.releaseConnection(db); // <---- Pool code!
}
}
}

}
If u r not understand the code,If ur the beginners that
prespective to
http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=/rzaha/poolnods.htm

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain reverse a linked list iterative solution in java?

496


What is a method header?

544


Explain restrictions on using enum?

630


If we don’t want some of the fields not to serialize how to do that?

564


How do you do descending order in java?

521






Describe the Big-O Notation.

615


Can a hashset contain duplicates java?

492


What is the final field modifier?

545


How many types of parsers are there?

544


What is the use of flag?

580


Is .net better than java?

552


How do you compare arrays in java?

504


What is the purpose of object oriented programming?

538


State two differences between C and Java.

691


What is bom encoding?

555