Question: jdbc question

Ads

 
 
 

Share on Google+Share on Google+

rajendra prasad
jdbc question
2 Answer(s)      8 years ago
Posted in : JDBC
Ads
View Answers

October 29, 2008 at 5:01 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


November 1, 2008 at 1:50 PM


Connection pooling is a technique sharing the server resources to the requestable clients. It increases the performance of the we application.. So everytime without creating a new connection it just activates and uses the old connection.

Ads









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
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  Hai , Give a steps for jdbc connectivity
JDBC
JDBC  why we use batch in jdbc
jdbc
jdbc  display the records using index in jdbc
JDBC
JDBC  How to add set of queries in a single query in JDBC
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  can u send me the code of jdbc how to join two tables that are in relation
Jdbc
Jdbc  A java program with jdbc connectivity with insert,delete,update options for name,regno,mark1,mark2,total
Tutorials   
Java Spring Hibernate Struts Training how to retrieve text and images from mysql database and show on html page using jsp servlet How to install Neo4j on Ubuntu 15.10? please help me in these prog MYSQL - mysql copy table to another table example by creating new table solution for mapping hibernate and pojos from net beans through database Connect GWT application with Oracle inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store This code have created jTable that connected with a database.every cell of last column have a button.But this button doesn't work properly.Where is the error java program Java Database Program jdbc Database connection class in a live project ..?? What is JDBC architecture? Unable to Create DSN for excel to ms access importing data and edit that data Database Scrolling Buttons how to use foreign key in java How to delete content of a log file from linux terminal? JSP-Oracle connectivity Student Management System Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same crud operations with foreign key constraint. I really need help with this assignment question Please help me out Please Backup Failed Mysqldump Got Errno 28 On Write Upgrade MySQL 5.1 to 5.5 in cpanel mysqldump all databases com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jpa.sequence' doesn't exist persistence xml class element persistence.xml for MySQL MySQL JDBC Driver pom dependency code Blob column jdk6 and oracle 8i connexion oracle 8i et jdk6 java [ cannot retrive date from sql ] why?? Order Entry System How to threow timeout exception when DB is not responding How to threow timeout exception when DB is not responding This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible make a method which takes user name & pwd as parameter & validate them against the database. If the corresponding user exist return true otherwise false. prabhakar validating credentials and displaying error message in login .jsp if not valid JDBC jdbc jdbc code register servlet vibhu connectiondetails from vibhu

Ads

 
Advertisement null

Ads