Home Answers Viewqa JDBC jdbc question

 
 


rajendra prasad
jdbc question
1 Answer(s)      4 years and 7 months ago
Posted in : JDBC

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 Pages:
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
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
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
= DriverManager.getConnection( "jdbc:mysql://localhost:3306/ATS", "root
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
jdbc
question is all about and that also reduce the chances to get answer quickly. So
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
jdbc  jdbc Expert:Ramakrishna Statement st1=con.createStatement... Deletion Example"); Connection con = null; String url = "jdbc:mysql://localhost...(); } } } hey here i want to romove using ResultSet. Did u read my question
Frame with JDBC - JDBC
Frame with JDBC  What is the Frame in JDBC?  Hello,What is the structure of table and in which format you wan't to display the data.Last time also you posted the same question.Answer me the above question and I
JDBC Connectivity - JDBC
JDBC Connectivity  my question is how to connect a Java program with MS-Access database?  Hello Use this code import java.sql.... String filename = "d:/java/mdbTEST.mdb"; String database = "jdbc
about jdbc - JDBC
about jdbc  Hi folks, my previous question was when "i have a table with primary key then when i enter a value which is already there will cause a problem how to solve it." i know to retrieve all the attributes
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
Java Question
"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost
swing question
= DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root
jdbc problom
jdbc problom  Deal All I have a very easy question. Please tell me lib folder name where i have to put my oracle connector file. Please also tell me the name of jar file
Java - JDBC
Java  Application program to add the database   Whenever you guys put question please write your query properly
j2ee - JDBC
j2ee  how to connect jsp to mysql   Hi, Thanks for asking question. I will tell you how you can connection to MySQL from JSP page... and then use JDBC api to connect to MySQL database. Following two tutorials shows how
jsp - JDBC
jsp  how to link jsp code with next htmlcode.  Hi keerthi, Can u explain ur question clearly? What is your exact Requirement
Update - JDBC
("jdbc:odbc:Biu"); stat = con.prepareStatement("Update Biu SET itemcode..., Your Question not posted properly so, Plz give again full details and full...://www.roseindia.net/jdbc/jdbc-mysql/UpdatesRecords.shtml Thanks  
Query regarding JSP, JDBC
Query regarding JSP, JDBC  can I get the code for the question asked by me regarding JSP,JDBC
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
java - JDBC
was recorded."); } } My question is how to connect this code
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
Data base related question
that element .how can i retrieve that element,using jdbc technology. please...; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con2=DriverManager.getConnection("jdbc
java project question
"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test
JSP Login Page Question
JSP Login Page Question  hey..i have a login page where different users first registered and then after they can login. my question is how a user...=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root
Jtable Question - Java Beginners
("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc
Java Programming Question
("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc
Java question - Swing AWT
= DriverManager.getConnection("jdbc:mysql://localhost:3306/register", "root", "root
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
Servlets and Jsp - JDBC
;Hi Friend, Please clarify your question. Thanks  first you post question clearly explaining the problem

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.