This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Web Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Web Application" Watch "Web Application" New topic
Author

Web Application

vishal sodani
Ranch Hand

Joined: Aug 26, 2000
Posts: 127
I am developing a web application,using JSP's,servlets and html.Now I want to test it on JSwdk.It is a database driven application.My problem is that I want to open a connection to the database once,and then use that connection object throughout my application.How can I do it in JSWDK?Please help!
Vlad Patryshev
Ranch Hand

Joined: Jun 30, 2001
Posts: 61
I have not clue what JSWDK is, but in JSP you can have application bean, and your singleton connection can be its attribute. (Or property, whatever.)


Thanks,<br />Vlad
vishal sodani
Ranch Hand

Joined: Aug 26, 2000
Posts: 127
After opening a connection with application bean,can I use the connection object throughtout in various servlets and jsp's?
DAYANAND BURAMSHETTY
Ranch Hand

Joined: Aug 06, 2001
Posts: 34
I think U can't because If U open connection this is useful for only one operation
after completion this operation U have to close this connection.For another
operation U have to open connection.
If I'm wrong.... Correct me


Dil se....,<BR>Dayanand<BR>0065-8839071(off)<BR>0065-7547034(Res0
Michael Arnett
Ranch Hand

Joined: Mar 22, 2001
Posts: 65
Hi all,
I believe one connection can be used for multiple operations, unless the specific db driver you are using does not allow this. I do know that each statement can have only one active resultset. Maybe you were thinking of that. Also, yes once an application bean's connection is initialized, it can used by any jsp / servlet. The code would look something like:
<jsp:useBean id="ConnectBeanId" scope="application" class="ConnectBean" />
Where ConnectBean is a class that looks like:
public class ConnectBean
{
Connection myConnection = null;
public ConnectBean
{
Class.forName(oracle.jdbc.driver.OracleDriver);
Connection myConnection = DriverManager.getConnection(jdbc: oracle:thin:scott/tiger@mysite.com:1521:myDb);
}
public boolean isClosed()
{
return myConnection.isClosed();
}
.
.
.
.
.
}

Later on another jsp page could have something like:
<jsp:useBean id="ConnectBeanId" scope="application" class="ConnectBean" />
<% if (ConnectBeanId.isClosed == true)
System.out.println ("You keep a-knocking but you can't come in!");
%>
In this scenario, if an instance of ConnectBean has already been instantiated, then the useBean directive will utilize that current instance rather than construct a new one (and all of its current members/properties will remain set to the current values/states)...otherwise it creates a new bean who's lifetime is set to application.
Hopefully this is helpful and/or legible and/or correct .
-MLA


[This message has been edited by Michael Arnett (edited August 08, 2001).]
[This message has been edited by Michael Arnett (edited August 08, 2001).]


Sun Certified Programmer for the Java 2 Platform 1.4
Vlad Patryshev
Ranch Hand

Joined: Jun 30, 2001
Posts: 61
There are different attitudes to connections, of course, but I would prefer to keep my connection open in my application bean and use it for all the database operations.
The other way is to delegate this responsibility to an application server.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Web Application
 
Similar Threads
JSF Database Access
what connection pooling is better?
data source and connection pooling ?
Connection Pooling in tomcat
database connectivity....