aspose file tools
The moose likes JDBC and the fly likes What is really a connection, statement? Can several sessions multiplex one connection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "What is really a connection, statement? Can several sessions multiplex one connection" Watch "What is really a connection, statement? Can several sessions multiplex one connection" New topic
Author

What is really a connection, statement? Can several sessions multiplex one connection

Allan Wang
Greenhorn

Joined: Apr 23, 2001
Posts: 20
Hi java fans,
When we use connection, is it really like a socket? But what is the statement? If I use only one connection in my servlet, can these sessions share one connection and haven't collisions?
Any one can throw some light on it.
allan
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3879
Connections aren't really like Sockets. They're well "connections" to the database. Think of them as being a part of the database moved over into your Java program.
The problem with sharing a single connection is that transactions in JDBC are done at the connection level. You most certainly do NOT want multiple servlet threads to participate in the same transaction. That's why the common solution is to pool them so that each thread gets one of N connections out of a pool and then releases it back to the pool when it's finished with its transaction.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Allan Wang
Greenhorn

Joined: Apr 23, 2001
Posts: 20
Kyle Brown, thanks very much.
You mean sharing a connection will affect the transactions result. I think what your mean is when I begin a transaction A and didn't commit, then I begin another transaction B in same connection and also didn't commit. Maybe for some reson, transaction A encounter some problem and rollbacked, so it will result in operations of transaction B will also be rollbacked. Is what I think right?
thanks,
allan
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: What is really a connection, statement? Can several sessions multiplex one connection
 
Similar Threads
Can i use only one connection and only one statement to execute multiple queries
Hibernate Connection Pool
Sessions Exceeded using Oracle 10g, Hibernate, Spring and Tomcat 5.5
Weird problem when using connection pool
Database connection management