Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

i create a connection..

Connection con =<created the="" connection="" with="" i="" am="" getting="" from="" jboss="">;

Using this same connection iam creating number of statements.

Statemetn st = con.Creatstatement();

Not only one . more number of statement.
using that i am performing some thread operation.

MYQuestion:

I am creating the statments. executing some quires. will these quires will process like concurrently or one by one which process..?
Posted
Comments
Akkywadhwa 20-Mar-13 5:38am    
one by one..
@BangIndia 20-Mar-13 6:04am    
Thanks..Then if i execute one query which is taking long time. then other will wait for that query completion?
Shubhashish_Mandal 20-Mar-13 8:04am    
It depends on how you implement. whether each thread separately perform to open connection/create statement/execute the statement then all the statement running concurrently, or you just executing multiple query using same Statement step by step , in that case it happens one by one
@BangIndia 20-Mar-13 8:29am    
Each thread won't open the new connection.
one connection , but i will create the new statement for each thread.
That time how it will work.?

As per JDBC 3.0 Specification "Each Connection object can create multiple Statement objects that may be used concurrently by the program."
 
Share this answer
 
It is also possible to pool the statements. Like as a prepared statement allows us to keep frequently used SQL statement in a pre-compile form, thus improving performance if that statement is executed multiple times. But there is a dark side of this. Creating a PreparedStatement object introduces a certain amount of overhead. There are some developers sometimes change their object models to increase the lifetime of a PreparedStatement object. Good thing is that JDBC 3.0 frees the developer from this, by making data source layer responsible for caching prepared statements.

The code snippet shows how to take advantage of JDBC's prepared statement pooling support.

Java Code:

String INSERT_BOOK_QUERY = "INSERT INTO BOOKLIST " +
                           "(AUTHOR, TITLE) " +
                           "VALUES (?, ?) ";
Connection conn = aPooledConnection.getConnection();
PreparedStatement ps = conn.prepareStatement(INSERT_BOOK_QUERY);
ps.setString(1, "Orwell, George");
ps.setString(2, "1984");
ps.executeUpdate();
ps.close();
conn.close();

// ...

conn = aPooledConnection.getConnection();
// Since the connection is from a PooledConnection, the data layer has
// the option to retrieve this statement from its statement pool,
// saving the VM from re-compiling the statement again.
PreparedStatement cachedStatement =
conn.prepareStatement(INSERT_BOOK_QUERY);
// ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900