jdbc question

jdbc question

View Answers

October 29, 2008 at 5:05 PM

Hi friend,


Connection Pooling :

A connection pool is a cache of database connections maintained by the database.
This results connections can be reused when the database receives future requests for data.
It is used to increase the performance of executing commands on a database.
It open and maintain a database connection for each user.

In JDBC connection pool, a pool of Connection objects is created at the time the application server (or some other server) starts.
These objects are then managed by a pool manager.When the connection pool server starts, it creates a predetermined
number of Connection objects.A client application would then perform a JNDI lookup to retrieve a reference to a
DataSource object that implements the ConnectionPoolDataSource interface. The ConnectionPoolDataSource would return a
Connection object that implemented the PooledConnection interface.

For example :

import java.sql.*;
import java.util.Properties;
import org.apache.commons.dbcp.*;
import org.apache.commons.pool.impl.*;
import org.apache.commons.pool.KeyedObjectPoolFactory;


public class JConPool {

public static void main(String args[]) throws Exception {

GenericObjectPool gObjPool = new GenericObjectPool();

Properties pros = new Properties();
pros.setProperty("Username", "root");
pros.setProperty("Password", "");
ConnectionFactory cf = new DriverConnectionFactory(new com.mysql.jdbc.Driver(),"jdbc:mysql://localhost/commons",pros);


KeyedObjectPoolFactory kopf =new GenericKeyedObjectPoolFactory(null, 8);

PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf,gObjPool,kopf, null, false, true);


for(int i = 0; i < 5; i++) {
gObjPool.addObject();
}


PoolingDriver poold = new PoolingDriver();
poold.registerPool("example", gObjPool);

for(int i = 0; i < 5; i++) {
gObjPool.addObject();
}

Connection connection = java.sql.DriverManager.getConnection("jdbc:apache:commons:dbcp:example");

System.err.println("Connection: " + connection );
PreparedStatement ps = connection.prepareStatement("Select * from tablename where id = ?");

System.err.println("Active: " + gObjPool.getNumActive() + ", Idle: " + gObjPool.getNumIdle());

connection.close();

System.err.println("Active: " + gObjPool.getNumActive() + ", Idle: " + gObjPool.getNumIdle());

}
}

---------------------------------------------

Visit for more information.

http://www.roseindia.net/jdbc/

http://www.roseindia.net/jsp/

Thanks









Related Tutorials/Questions & Answers:
Jdbc Question
Jdbc Question  Hi. In Jdbc, if i am pointing to the database of some other machine, i mean instead of local-host i give the ip of that machine and that machine is shut down, Will my connection still work
jdbc question - JDBC
jdbc question   Up to now i am using just connection object for jdbc... a database connection for each user. In JDBC connection pool, a pool of Connection...(),"jdbc:mysql://localhost/commons",pros); KeyedObjectPoolFactory kopf =new
Advertisements
jdbc question - JDBC
jdbc question   Up to now i am using just connection object for jdbc... a database connection for each user. In JDBC connection pool, a pool of Connection...(),"jdbc:mysql://localhost/commons",pros); KeyedObjectPoolFactory kopf =new
jdbc interview question
how does java interact with databases? jdbc interview question  how... using jdbc? can you explain in short how you go about using jdbc api in code...: http://www.roseindia.net/jdbc/jdbc-mysql/MysqlConnect.shtml http
Jdbc MS-Access question
Jdbc MS-Access question  How to delete records from the three table in MS-Access? They are in relationship with each other regarding to data field
Jdbc MS-Access question
Jdbc MS-Access question  How to delete records from the three table in MS-Access? They are in relationship with each other regarding to data field
jdbc interview question
drivers in JDBC. JDBC interview question  what are the adv and disadv dirver1,2,3,4? expain type 1,type 2,type 3,type 4 drivers in jdbc... such as the jdbc-odbc bridge. They rely on an intermediary such as ODBC to transfer
jdbc interview question
of columns. JDBC ResultSet Example RowSet: A RowSet object contains a set of rows from.... JDBC RowSet Example ResultSetMetaData: ResultSetMetaData is a class which.... JDBC details interrogation can be done by using ResultSetMetaData. It includes
Interview question - JDBC
Interview question   Hi Friends, What is the return type of execute mehtod in jdbc .Thanks  Hi Rajendra, Whatever it may be the statement type, like java.sql.Statement
Ask JDBC question online
Ask JDBC question online   ... of Roseindia, we are pleased to inform you that we have just begun a new question-answer service ‘Ask Question in JDBC’ for all our visitors. Now you
Simple Question - JDBC
jdbc interview question
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
Question
Question   When there is an exception in my program how java runtime system handles
question
question  dear sir/madam my question is how to compare two text format in java..we are java beginners..so we need the complete source code for above mentioned question...we have to compare each and every word
question
question  Dear sir i had some typing mistake at previous question so its my humble request to let me know the steps to start the tomcat6 under the tomcat directory
question
question  Dear Sir, could you please send me a simple example of java and database connectivity with java and sql   Please visit the following link: JDBC Tutorials
question
question  I am doing a project using struts framework and spring jdbc .I have a issue that when data is inserted into database if we click the refresh button then the same data is again inserted in to the database.What
question
in Jdbc -jsp page . that's it. chandu
Question
(); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost
question
question  Gud morning sir, I have asked u some question regarding jsp in saturaday for that i didnot find any answere in which u send me the some of the links.U have asked me the specify some details. There is a entity name
Question?
Question?  My question is how to: Add a menu bar to the program with a File menu. In the File menu, add a submenu (JMenuItem) called About. When the user clicks on the About menu item, display a JOptionPane message dialog
question
= DriverManager.getConnection( "jdbc:mysql://localhost:3306/ATS", "root
jdbc - JDBC
drivers for concurrent access?   Question: Is the JDBC-ODBC Bridge multi-threaded? Answer: No. The JDBC-ODBC Bridge does not support concurrent access from different threads. The JDBC-ODBC Bridge uses synchronized methods
JDBC
JDBC  why we use batch in jdbc
jdbc
jdbc  display the records using index in jdbc
jdbc
jdbc  Hai , Give a steps for jdbc connectivity
JDBC
JDBC  How to add set of queries in a single query in JDBC
jdbc
jdbc  please tell me sir.i dont know JDBC connection and how to create table in database
jdbc
jdbc   how to write program to save data and retrieve data from the form in Java
jdbc
jdbc  why do we need to load jdbc drivers before connecting to database
JDBC
JDBC  how to set classpath for eclipse, java, where to copy jdbc connector
JDBC
JDBC  in class.forname which driver name we are writing for the connection from jdbc to sqlserver 2008
jdbc
jdbc  is it possible to use doget & dopost method with jdbc to call in a servlet programe
Jdbc
Jdbc  A java program with jdbc connectivity with insert,delete,update options for name,regno,mark1,mark2,total
JDBC
JDBC  can u send me the code of jdbc how to join two tables that are in relation
jdbc - JDBC
Why JDBC   JDBC used for what
JDBC - JDBC
JDBC - limitations of jdbc  What are the limitations of JDBC
jdbc
jdbc define batch updates  define batch updates?exp   JDBC... links: http://www.roseindia.net/jdbc/Jdbc-batch-update.shtml http://www.roseindia.net/tutorial/java/jdbc/batchupdateresultsetexample.html
jdbc
jdbc  Write a web based student registration application where the students can register online with their enrollment no. You are required to use JSP, Servelet and JDBC
JDBC
JDBC save a data in the database  I need a code to save a data... between java and mysql using JDBC and saves the data into the database. import... con = null; String url = "jdbc:mysql://localhost:3306/"; String db
JDBC
JDBC code to save a data in the database  I need a code to save... the connection between java and mysql using JDBC and saves the data into the database...!"); Connection con = null; String url = "jdbc:mysql://localhost:3306/"; String db
jdbc
how can we set transaction level through jdbc api  how can we set transaction level through jdbc api   Use Connection.setTransactionIsolation(int) to set the desired tansaction level, which takes one of the 5 arguments
jdbc
how can we call stored procedure using jdbc  how can we call stored procedure using jdbc   Call a Stored Procedure using...(); For more information, visit the following link: JDBC call Stored Procedure
jdbc - JDBC
Java JDBC application  Database Application in Java JDBC
JDBC - JDBC
JDBC Select Count Example   Need an example of count in JDBC
JDBC - JDBC
JDBC -statement types in jdbc  statement types in jdbc
jdbc - JDBC
Loading JDBC driver at runtime  How to load JDBC Driver at runtime
jdbc
jdbc  hey sir i just wanna have some ppt on jdbc coz have my exams next week and i have not attended any classes coz of job... I m studyng frm niit

Ads