Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Driver Loading

 
Zoram Paul
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

I am creating an application. I know that for database purpose I have to load the drivers, create connection object and make the Statements and PreparedStatement object. But I don't have to load the driver in every page where database access is required. Or I hope I don't have to create Connection Object in every page too, So what should I do for the application to be developed in an efficient manner. Please help me. Please advice me.

Thanking you a lots.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at a Connection Pool Manager like DBCP
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The driver only needs to be loaded once, possibly at startup time. For using connections it's customary to use a connection pool in web applications, which your servlet container may provide for you (e.g. Tomcat does).

And, of course, it's considered bad design to do anything DB-related in a JSP. Please consider doing DB access in a backing bean or a proper class.
 
Amit Kumargupta
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the Connection Pooling
 
Ashok Mor
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Zoram Paul,

One way is that you can go with connection pooling, but for that you need to have is an Application Server.

But I think you just want run JDBC code in which no need to load driver each and every time right?

For that you can use Singleton class which can be used to get Connection object and will also load the driver only once. Like below.





���



..


Use can use this class any where within applcaiton like

..
..
Connection con = ConnectionManager.getConnection(�Driver� , �URL�);

OR like

..
..




Thanks,

Ashok Mor
Ness Technology, Bangalore.

[ July 19, 2007: Message edited by: Ashok Mor ]
[BPSouther: Added code tags]
[ July 19, 2007: Message edited by: Ben Souther ]
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ashok Mor:
One way is that you can go with connection pooling, but for that you need to have is an Application Server.


No application server or servlet container is needed to use a connection pool. They can provide one as part of the server infrastucture (as was pointed out above), but in general, pools are independent of the environment they run in.


This kind of lazy instantiation is not thread-safe, and must not be used in a web application, unless further synchronization measures are used to protect it.
[ July 19, 2007: Message edited by: Ulf Dittmer ]
 
Ashok Mor
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right, we need to use zynchronized keyword against these methods....

Servlet container is nothing to do with Connection pooling...Am I right Mr. Ulf Dittmer?



But of course I will be intrested Mr. Ulf Dittmer, that how can we implement Connection Pooling without any server resource like an Application Server?


Where will you create pool to store the the instance of Connection?

Who will be responsible for managing all these operation of connection pool??

_____________
Ashok Mor
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64688
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ashok Mor:

One way is that you can go with connection pooling, but for that you need to have is an Application Server.


This is the JSP forum. It's a given that there will be a server.

Most experienced web developers will rely upon container-managed connection pooling.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18094
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For those who might be interested, one popular JDBC connection pool manager is the dbcp connection pooler available from the Apache Jakarta Commons. It is the default connection pooler for Tomcat and can be used with any Java app that needs a JDBC connection pooler, not just application servers.

dcbp is built on top of other Jakarta Commons - in particular, it uses a generic object pooler to manage the connection objects.

If you're using an application server - and if you're working with JSPs you haven't got much choice - you can expect that it will support a database connection pool.
 
Ashok Mor
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:


This is the JSP forum. It's a given that there will be a server.

Most experienced web developers will rely upon container-managed connection pooling.


Yes Bear Bibeault, You are right, but for that we need to have a cotianer at server na?

So it might be in ApplicationServer or any other Server.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't make use of the colloquial words like "na" in these context Ashok. Please make use of RealWords .



First of all, having the connection instance "public" may totally collapse the purpose as its static as well. Please always have the instance variables "private" in these scenarios. and ensure they are obtained ONLY via the appropriate methods (preferably static).

HtH.
 
Ashok Mor
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raghavan Muthu:
Don't make use of the colloquial words like "na" in these context Ashok. Please make use of RealWords .



First of all, having the connection instance "public" may totally collapse the purpose as its static as well. Please always have the instance variables "private" in these scenarios. and ensure they are obtained ONLY via the appropriate methods (preferably static).

HtH.


Raghavan Muthu, you are right that we should use only infromative words only, But here 'na' is nothing, because in hindi what we say? even though if you have any dictionary to use please let me know.
 
Prem Kashyap
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we all should better concentrate in providing the solution rather then letting our egos clash. Lets keep our sentence related to technology only.

Regards
Prem Kashyap
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs run in servlet containers.
Most, if not all, up to date servlet containers provide connection pooling.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I think we all should better concentrate in providing the solution rather then letting our egos clash


I think there is nothing called 'ego' and 'clash' here prem. Just i thought of directing Ashok towards the rules being followed here so that we will be conscious in our further usages right.

Ashok, i also know the meaning of "na". Have you read the link pointing to "UseRealWords"? If any one who reads this post and does not have the knowledge in Hindi (or any other language which we know), they will have a tough time in understanding this. Not just speaking in this "na" context but just to avoid any further usages in future.

Hope this clears and helps!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64688
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ashok Mor:
because in hindi what we say? even though if you have any dictionary to use please let me know.


Please be sure to use real English words when posting to the forums.
 
Zoram Paul
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[removed non related question]
[ July 26, 2007: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zoram Paul,
Please use this forum for JSP related questions only.
Thanks,
-Ben
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic