JDBC Internals

Hello Every body,

I am interested to know about the internal happenings of Java database connectivity. Right from start to end and also please clarify me on the following questions.

1. what happens when a database connection is created and closed?

2. What resources on the database side will be used if do not close the connection? Is it a serious problem?

3. Is it adviseable to open a connection for each request in web application? If not please let me know which technique to use.

Cheers,

Divakar

[543 byte] By [bdsaia] at [2007-10-2 7:54:28]
# 1

> Hello Every body,

>

> I am interested to know about the internal happenings

> of Java database connectivity. Right from start to

> end and also please clarify me on the following

> questions.

Well, that would be about a very big book to cover all of that. In fact, there are already several out there....

>

> 1. what happens when a database connection is created

> and closed?

Lots and lots and lots, and it depends on which database and which driver.

> 2. What resources on the database side will be used

> if do not close the connection? Is it a serious

> problem?

It depends a lot on the particular database and driver; serious problems can result, such as causing the database to crash.

> 3. Is it adviseable to open a connection for each

> request in web application? If not please let me know

> which technique to use.

No, using a connection pool is very strongly advised. Either use the "search forums" feature, to the left, or use Google, looking for "connection pooling". Also, take a look at Apache's DBCP.

If you hanven't read the Sun JDBC tutorial yet, do that too.

http://java.sun.com/docs/books/tutorial/jdbc/

StuDerbya at 2007-7-16 21:43:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

> 2. What resources on the database side will be used

> if do not close the connection? Is it a serious

> problem?

yeah, although it's not the end of the world

the connection will timeout eventually

but you should ALWAYS proactively close it

> 3. Is it adviseable to open a connection for each

> request in web application? If not please let me know

> which technique to use.

no, NEVER do that

almost all web apps support multiple users

if you are opening and closing often, you're performance will suffer

better to pool 10-25 (or whatever) connections and reuse them

when the web app shuts down, THEN you can close them

>

> Cheers,

> Divakar

SoulTech2012a at 2007-7-16 21:43:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...