• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database Connection from JNDI Datasource vs DriverManager

 
Aayush Singhal
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a fairly simple problem :

Retrieve a list of elements from a table (Oracle Database) using a single query. And iterate the ResultSet to print the result to console.

I have made 2 sample codes :
1. uses the JNDI lookup to retrieve the DataSource object from the JBoss 5.1 server and then get the connection from this datasource.
2. uses the DriverManager.getconnection(...) to get the connection directly from the database.

Then I execute the query and iterate the resultset.

Somehow, when I get the connection from the JNDI lookedup datasourrce, the resultset iteration takes long time. almost 500ms for each row. While when the connection from the database is directly used to obtain the connection, it instantaneously prints 10 records then the next 10 (the ResultSet.setFetchSize is 10 by default) so it is working fine.

I am not able to understand why the connection from the JNDI lookedup datasource is acting up....

Technically there shouldn't be any difference between the two as connection is fetched only once and only a single query is executed (so no connection pooling comes into the picture I believe) .

Any insights would be really appreciated. Thanks

Here's the code :



 
Campbell Ritchie
Sheriff
Posts: 51349
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll try duplicating your discussion in a databases forum, in the hope of getting more attention.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic